 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 6th, 2006, 04:10 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Double records inserted when using Insert
Hi Everyone,
I'm having a problem inserting data into SQL Server. Everytime i run the following query in ASP, it enters two records instead of one:
rsQuery = "INSERT INTO Merchants (Merchant_Name, Merchant_Short_Description, Partner_Of_Choice, Merchant_Rating, Category_ID, Landing_Page_URL, Merchant_Logo_120x60, Merchant_URL, Appear_On_Site) " & _
"VALUES ('"& strMerchant_Name &"', '"& strMerchant_Desc &"', '"& intPOC &"', '"& intMerchant_Rating &"', '"& intCategoryID &"', '"& strLanding_Page_URL &"', '"& strMerchant_Logo_URL &"', '"& strMerchant_URL &"', '"& intAppear_On_Site2 &"')"
objDBInsert.open rsQuery, DBConn
I really do not know what's happening here. I've been searching on the net but so far haven't been able to find a solution to the problem.
I've ran this query in SQL Server Query Analyser and it only enters the one record!!!!
Can someone help me out cause this is driving me nuts!!!!
Many thanks,
Sach
|
|

March 6th, 2006, 05:06 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Sach,
Quote:
|
quote:I've ran this query in SQL Server Query Analyser and it only enters the one record!!!!
|
If the query is good, then you must be executing it twice. Look for code that opens the recordset again, or for code that calls the function that contains the code above and make sure it's only called once....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 7th, 2006, 05:23 AM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
I've been through the code twice now and the insert query is not being called again anywhere. Here's the code in full:
<%@ Language="VBScript"%>
<% option explicit %>
<%
' ******* REQUESTS INFO FROM Edit.asp FOR ALL Merchant info
strTableName = request.QueryString("TableName")
intMerchant_ID = request.QueryString("MerchantID")
intAppear_On_Site = request.QueryString("Appear_On_Site")
strMerchantType = request.QueryString("MerchantType")
'******** VALUES FOR MERCHANTS TABLE ********************
strMerchant_Name = request.Form("Merchant_Name")
strMerchant_Desc = request.Form("Merchant_Description")
intPOC = request.Form("POC")
intPOC = Cint(intPOC)
strLanding_Page_URL = request.Form("Landing_Page_URL")
intMerchant_Rating = request.Form("Merchant_Rating")
intMerchant_Rating = Cint(intMerchant_Rating)
intCategoryID = request.Form("Category_Name")
strMerchant_Logo_URL = request.Form("Merchant_Logo_URL")
strMerchant_Logo_URL = replace(strMerchant_Logo_URL,"'","''")
strMerchant_Logo_URL = replace(strMerchant_Logo_URL,CHR(34),CHR(34))
strMerchant_URL = request.Form("Merchant_URL")
intAppear_On_Site2 = request.Form("Appear_On_Site")
intAppear_On_Site2 = Cint(intAppear_On_Site2)
'********* VALUES FOR BANNERS TABLE ***************************
strBanner_Set_Desc = request.Form("Banner_Set_Desc")
strBanner120x600 = request.Form("strBanner120x600")
strBanner120x600 = replace(strBanner120x600,"'","''")
strBanner120x600 = replace(strBanner120x600,CHR(34),CHR(34))
strBanner468x60 = request.Form("strBanner468x60")
strBanner468x60 = replace(strBanner468x60,"'","''")
strBanner468x60 = replace(strBanner468x60,CHR(34),CHR(34))
strBanner234x60 = request.Form("strBanner234x60")
strBanner234x60 = replace(strBanner234x60,"'","''")
strBanner234x60 = replace(strBanner234x60,CHR(34),CHR(34))
strBanner120x240 = request.Form("strBanner120x240")
strBanner120x240 = replace(strBanner120x240,"'","''")
strBanner120x240 = replace(strBanner120x240,CHR(34),CHR(34))
strBanner120x120 = request.Form("strBanner120x120")
strBanner120x120 = replace(strBanner120x120,"'","''")
strBanner120x120 = replace(strBanner120x120,CHR(34),CHR(34))
strBanner120x60 = request.Form("strBanner120x60")
strBanner120x60 = replace(strBanner120x60,"'","''")
strBanner120x60 = replace(strBanner120x60,CHR(34),CHR(34))
intAvailable_In_Cat_120x600 = request.Form("intAvailable_In_Cat_120x600")
intAvailable_In_Cat_468x60 = request.Form("intAvailable_In_Cat_468x60")
intAvailable_In_Cat_234x60 = request.Form("intAvailable_In_Cat_234x60")
intAvailable_In_Cat_120x240 = request.Form("intAvailable_In_Cat_120x240")
intAvailable_In_Cat_120x120 = request.Form("intAvailable_In_Cat_120x120")
intAvailable_In_Cat_120x60 = request.Form("intAvailable_In_Cat_120x60")
intBanner_Available_On_Site = request.Form("intBanner_Available_On_Site")
intBanner_Available_Homepage = request.Form("intBanner_Available_Homepage")
Set objDBInsert = Server.CreateObject("ADODB.Recordset")
rsQuery = "INSERT INTO Merchants (Merchant_Name, Merchant_Short_Description, Partner_Of_Choice, Merchant_Rating, Category_ID, Landing_Page_URL, Merchant_Logo_120x60, Merchant_URL, Appear_On_Site) " & _
"VALUES ('"& strMerchant_Name &"', '"& strMerchant_Desc &"', '"& intPOC &"', '"& intMerchant_Rating &"', '"& intCategoryID &"', '"& strLanding_Page_URL &"', '"& strMerchant_Logo_URL &"', '"& strMerchant_URL &"', '"& intAppear_On_Site2 &"')"
objDBInsert.open rsQuery, DBConn
objDBInsert.Close
Set objDBInsert = NOTHING
%>
I'm not too sure but i'm starting to suspect there may be an issue with SQL Server as i've check other code i;ve worked on and the Insert Query is exactly the same but i was using Access before.
If anyone could shed some light on this i would really appreciate the help.
Many thanks,
Sachin
|
|

March 7th, 2006, 05:39 AM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Found the answer!! The form was being submitted twice from the previous page, d'ho!!!
|
|

March 7th, 2006, 02:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yeah, it had to be something like this...
Glad it's working now...
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |