parallon
03-27-2007, 12:53 AM
Hello all. I am not too familiar with using multiple recordsets to insert multiple records at one time, so my code may be a little 'laughable', but here it goes.
What I am wanting to do is to create a record in one table, and then get the ID (Autonumber) of that record and use it to populate a field in another table called LinkId. Here is what I have so far:
<%
Dim oConn, oRS, sQry
Dim sConn
set oConn = Server.CreateObject("ADODB.Connection")
'Relpace Xxxxx with the name of your dsn
sConn = MM_timesheet_STRING
oConn.Open sConn
Set oRS = Server.CreateObject("ADODB.Recordset")
Set oRS.ActiveConnection = oConn
'SQL RecordSet
sQry = "INSERT INTO tblEquipment (EqNum, EqDesc, Active) VALUES ('" & EqNum & "', '" & EqDesc & "', -1)"
oRS.Open sQry
'oRS.Close()
'Set oRS = Nothing
%>
<%
Dim oConn2, oRS2, sQry2
Dim sConn2
set oConn2 = Server.CreateObject("ADODB.Connection")
'Relpace Xxxxx with the name of your dsn
sConn2 = MM_timesheet_STRING
oConn2.Open sConn2
Set oRS2 = Server.CreateObject("ADODB.Recordset")
Set oRS2.ActiveConnection = oConn2
'SQL RecordSet
sQry2 = "SELECT ID FROM tblEquipment WHERE EqNum = '" & EqNum & "'"
oRS2.Open sQry2
' ------------------------------------------------
LinkId = oRS2("ID")
Response.Write("LinkId = " & LinkId & "<BR>") ' For testing purposes
%>
Well, what is happening is that I am getting the following error:
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/Equipment/Eq_AddEdit2.asp, line 74
... but if I refresh the page, it works, although now I have 2 identical records in the first table (except for the Autonumber of course). It seems like the second SQL statement is trying to read the table before the first one actually finished writing to the DB.
Any suggestions would be greatly appreciated.
Thanks,
Parallon
What I am wanting to do is to create a record in one table, and then get the ID (Autonumber) of that record and use it to populate a field in another table called LinkId. Here is what I have so far:
<%
Dim oConn, oRS, sQry
Dim sConn
set oConn = Server.CreateObject("ADODB.Connection")
'Relpace Xxxxx with the name of your dsn
sConn = MM_timesheet_STRING
oConn.Open sConn
Set oRS = Server.CreateObject("ADODB.Recordset")
Set oRS.ActiveConnection = oConn
'SQL RecordSet
sQry = "INSERT INTO tblEquipment (EqNum, EqDesc, Active) VALUES ('" & EqNum & "', '" & EqDesc & "', -1)"
oRS.Open sQry
'oRS.Close()
'Set oRS = Nothing
%>
<%
Dim oConn2, oRS2, sQry2
Dim sConn2
set oConn2 = Server.CreateObject("ADODB.Connection")
'Relpace Xxxxx with the name of your dsn
sConn2 = MM_timesheet_STRING
oConn2.Open sConn2
Set oRS2 = Server.CreateObject("ADODB.Recordset")
Set oRS2.ActiveConnection = oConn2
'SQL RecordSet
sQry2 = "SELECT ID FROM tblEquipment WHERE EqNum = '" & EqNum & "'"
oRS2.Open sQry2
' ------------------------------------------------
LinkId = oRS2("ID")
Response.Write("LinkId = " & LinkId & "<BR>") ' For testing purposes
%>
Well, what is happening is that I am getting the following error:
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/Equipment/Eq_AddEdit2.asp, line 74
... but if I refresh the page, it works, although now I have 2 identical records in the first table (except for the Autonumber of course). It seems like the second SQL statement is trying to read the table before the first one actually finished writing to the DB.
Any suggestions would be greatly appreciated.
Thanks,
Parallon