|
 |
asp_databases thread: two records, one submit
Message #1 by koery.nelson@i... on Tue, 24 Apr 2001 13:55:58
|
|
Using the following code to write data from a from to a MS Access database
I get two records created each time the submit button is pressed. The
first records contains the correct data, the second records is empty
except for the autonumber, and date fields. (In the database, I am using
Autonumber, and the Date is entered automatically with the Now()
statement.)
<%
Dim sql, MyConn, RS, strBarCode, strDescription, strMake, strModel,
strSerial, strCCenter, strLocation, strRoom, strUser, strName,
strTelephone
strBarCode= Request.Form("Barcode")
strDescription= Request.Form("Description")
strMake= Request.Form("Make")
strModel= Request.Form("Model")
strSerial= Request.Form("Serial")
strCCenter= Request.Form("CCenter")
strLocation= Request.Form("Location")
strRoom= Request.Form("Room")
strUser= Request.Form("User")
strName= Request.Form("Name")
strTelephone= Request.Form("Telephone")
Set MyConn=Server.CreateObject("ADODB.Connection")
Set RS=Server.CreateObject("ADODB.RecordSet")
MyConn.Open =("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\TempDrive\myDataBase.mdb")
RS.Open "Select * from tblAssets", MyConn, adOpenDynamic,
adLockPessimistic, adCMDText
RS.AddNew
RS("Barcode")= strBarCode
RS("Description")= strDescription
RS("Make")= strMake
RS("Model")= strModel
RS("Serial")= strSerial
RS("CCenter")= strCCenter
RS("Location")= strLocation
RS("Room")= strRoom
RS("User")= strUser
RS("Name")= strName
RS("Telephone")= strTelephone
RS.Update
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
%>
Thanks in advance,
Nels
Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 24 Apr 2001 18:35:50 +0200
|
|
Hi there,
Is this all the code in the page? Are you sure you are not accidentally
redirecting the page to itself and do another submit?
Also, you might consider changing your AddNew and Update combination to a
straight SQL insert command. This is not really a solution to your problem
(with the code below a double insert shouldn't happen) but it will perform
better and give you a clearer idea of what is actually going on.
If this doesn't help, I suggest you post the complete page.
HtH
Imar
At 01:55 PM 4/24/2001 +0000, you wrote:
>Using the following code to write data from a from to a MS Access database
>I get two records created each time the submit button is pressed. The
>first records contains the correct data, the second records is empty
>except for the autonumber, and date fields. (In the database, I am using
>Autonumber, and the Date is entered automatically with the Now()
>statement.)
>
><%
>Dim sql, MyConn, RS, strBarCode, strDescription, strMake, strModel,
>strSerial, strCCenter, strLocation, strRoom, strUser, strName,
>strTelephone
>
>strBarCode= Request.Form("Barcode")
>strDescription= Request.Form("Description")
>strMake= Request.Form("Make")
>strModel= Request.Form("Model")
>strSerial= Request.Form("Serial")
>strCCenter= Request.Form("CCenter")
>strLocation= Request.Form("Location")
>strRoom= Request.Form("Room")
>strUser= Request.Form("User")
>strName= Request.Form("Name")
>strTelephone= Request.Form("Telephone")
>
>
>Set MyConn=Server.CreateObject("ADODB.Connection")
>
>Set RS=Server.CreateObject("ADODB.RecordSet")
>MyConn.Open =("Provider=Microsoft.Jet.OLEDB.4.0;Data
>Source=C:\TempDrive\myDataBase.mdb")
>
>RS.Open "Select * from tblAssets", MyConn, adOpenDynamic,
>adLockPessimistic, adCMDText
>
>RS.AddNew
>RS("Barcode")= strBarCode
>RS("Description")= strDescription
>RS("Make")= strMake
>RS("Model")= strModel
>RS("Serial")= strSerial
>RS("CCenter")= strCCenter
>RS("Location")= strLocation
>RS("Room")= strRoom
>RS("User")= strUser
>RS("Name")= strName
>RS("Telephone")= strTelephone
>RS.Update
>
>RS.Close
>MyConn.Close
>Set RS = Nothing
>Set MyConn = Nothing
>
>%>
>
>Thanks in advance,
>
>Nels
Message #3 by "Charles Feduke" <webmaster@r...> on Tue, 24 Apr 2001 15:46:35 -0400
|
|
Not sure what bug you're running into, but you could always just use a
connection and execute a SQL statement:
Dim conConnection
Set conConnection = Server.CreateObject("ADODB.Recordset")
conConnection.Open sYourConnectionString
conConnection.Execute "INSERT INTO table (name, rank, ssn) VALUES ('Chuck',
'Cpl', '00000000')", , adExecuteNoRecords
- Chuck
----- Original Message -----
From: <koery.nelson@i...>
To: "ASP Databases" <asp_databases@p...>
Sent: Tuesday, April 24, 2001 1:55 PM
Subject: [asp_databases] two records, one submit
> Using the following code to write data from a from to a MS Access database
> I get two records created each time the submit button is pressed. The
> first records contains the correct data, the second records is empty
> except for the autonumber, and date fields. (In the database, I am using
> Autonumber, and the Date is entered automatically with the Now()
> statement.)
>
> <%
> Dim sql, MyConn, RS, strBarCode, strDescription, strMake, strModel,
> strSerial, strCCenter, strLocation, strRoom, strUser, strName,
> strTelephone
>
> strBarCode= Request.Form("Barcode")
> strDescription= Request.Form("Description")
> strMake= Request.Form("Make")
> strModel= Request.Form("Model")
> strSerial= Request.Form("Serial")
> strCCenter= Request.Form("CCenter")
> strLocation= Request.Form("Location")
> strRoom= Request.Form("Room")
> strUser= Request.Form("User")
> strName= Request.Form("Name")
> strTelephone= Request.Form("Telephone")
>
>
> Set MyConn=Server.CreateObject("ADODB.Connection")
>
> Set RS=Server.CreateObject("ADODB.RecordSet")
> MyConn.Open =("Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\TempDrive\myDataBase.mdb")
>
> RS.Open "Select * from tblAssets", MyConn, adOpenDynamic,
> adLockPessimistic, adCMDText
>
> RS.AddNew
> RS("Barcode")= strBarCode
> RS("Description")= strDescription
> RS("Make")= strMake
> RS("Model")= strModel
> RS("Serial")= strSerial
> RS("CCenter")= strCCenter
> RS("Location")= strLocation
> RS("Room")= strRoom
> RS("User")= strUser
> RS("Name")= strName
> RS("Telephone")= strTelephone
> RS.Update
>
> RS.Close
> MyConn.Close
> Set RS = Nothing
> Set MyConn = Nothing
>
> %>
>
> Thanks in advance,
>
> Nels
>
Message #4 by "Nelson, Koery" <Koery.Nelson@i...> on Tue, 24 Apr 2001 16:06:03 -0400
|
|
Thanks to an earlier response from Imar, I am using the Insert Into
statement and am
getting the results I expected. Still am not sure where the second (empty
record) was
coming from. Another day.
Thanks again!
Koery Nelson
-----Original Message-----
From: Charles Feduke [mailto:webmaster@r...]
Sent: Tuesday, April 24, 2001 3:47 PM
To: ASP Databases
Subject: [asp_databases] Re: two records, one submit
Not sure what bug you're running into, but you could always just use a
connection and execute a SQL statement:
Dim conConnection
Set conConnection = Server.CreateObject("ADODB.Recordset")
conConnection.Open sYourConnectionString
conConnection.Execute "INSERT INTO table (name, rank, ssn) VALUES ('Chuck',
'Cpl', '00000000')", , adExecuteNoRecords
- Chuck
----- Original Message -----
From: <koery.nelson@i...>
To: "ASP Databases" <asp_databases@p...>
Sent: Tuesday, April 24, 2001 1:55 PM
Subject: [asp_databases] two records, one submit
> Using the following code to write data from a from to a MS Access database
> I get two records created each time the submit button is pressed. The
> first records contains the correct data, the second records is empty
> except for the autonumber, and date fields. (In the database, I am using
> Autonumber, and the Date is entered automatically with the Now()
> statement.)
>
> <%
> Dim sql, MyConn, RS, strBarCode, strDescription, strMake, strModel,
> strSerial, strCCenter, strLocation, strRoom, strUser, strName,
> strTelephone
>
> strBarCode= Request.Form("Barcode")
> strDescription= Request.Form("Description")
> strMake= Request.Form("Make")
> strModel= Request.Form("Model")
> strSerial= Request.Form("Serial")
> strCCenter= Request.Form("CCenter")
> strLocation= Request.Form("Location")
> strRoom= Request.Form("Room")
> strUser= Request.Form("User")
> strName= Request.Form("Name")
> strTelephone= Request.Form("Telephone")
>
>
> Set MyConn=Server.CreateObject("ADODB.Connection")
>
> Set RS=Server.CreateObject("ADODB.RecordSet")
> MyConn.Open =("Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\TempDrive\myDataBase.mdb")
>
> RS.Open "Select * from tblAssets", MyConn, adOpenDynamic,
> adLockPessimistic, adCMDText
>
> RS.AddNew
> RS("Barcode")= strBarCode
> RS("Description")= strDescription
> RS("Make")= strMake
> RS("Model")= strModel
> RS("Serial")= strSerial
> RS("CCenter")= strCCenter
> RS("Location")= strLocation
> RS("Room")= strRoom
> RS("User")= strUser
> RS("Name")= strName
> RS("Telephone")= strTelephone
> RS.Update
>
> RS.Close
> MyConn.Close
> Set RS = Nothing
> Set MyConn = Nothing
>
> %>
>
> Thanks in advance,
>
> Nels
>
|
|
 |