I have a customer who wants to be able to upload updates to his database as access files. These access files will contain a table called parts which contains the records to be merged with the existing "main" database (which also has a table called parts, into which these new (or updated) parts should go).
I have tried to create a subroutine to merge the two recordsets, so that if the data in the new parts table matches that in the old, the old data gets overwritten, otherwise the data should be added to the old table. Unfortunately I've come up against a brick wall in the form of one of ASPs lovely incomprehensible, and often wildly inaccurate, error messages. I can't figure out where I've gone wrong and I've a feeling my changes to the code are just making things worse at this stage. Below is the sub which, supposedly, merges the recordsets. I know it's probably totally wrong, but it's all I've got. Some of the lines are quite long and may get wrapped in peculiar places.
private sub mergeDB (newdb, olddb)
Dim dbc
dim dbc2
Dim strConn
dim strConn2
dim rs
dim rs2
strConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& olddb
strConn2 = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& newdb
Set dbc = Server.CreateObject("ADODB.Connection"
set dbc2 =server.createobject("adodb.connection"
dbc.open strConn
dbc2.open strConn2
strSQL2="SELECT * FROM parts"
set rs2=server.createobject("adodb.recordset"
rs2.open strSQL2, dbc2, adOpenStatic, adLockReadOnly, adCmdText
while not rs2.eof
strSQL="select * from parts where partno='" & rs2("partno"
& "'"
set rs=server.createobject("adodb.recordset"
rs.open strSQL, dbc, adOpenKeyset, adLockOptimistic, adCmdText
while not rs.eof
for each i in rs.fields
if rs2.fields(i)<>"" then rs.fields(i)=rs2.fields(i)
next
rs.movenext
wend
if rs.eof then
rs.addnew
for each i in rs.fields
if rs2.fields(i)<>"" then
rs.fields(i)=rs2.fields(i)
else
rs.fields(i)=""
end if
next
rs.update
end if
rs.close
set rs=nothing
rs2.movenext
wend
rs2.close
set rs2=nothing
dbc.close
set dbc=nothing
dbc2.close
set dbc2=nothing
End sub
The error I get when running the above code is:
ADODB.Recordset error '800a0bb9'
The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.
/indespension/Loader.asp, line 248
Line 248 contains the code "rs2.open strSQL2, dbc2, adOpenStatic, adLockReadOnly, adCmdText", which I can't see any problem with.
If anyone can a) see what I've done wrong or b) offer a different solution to this problem I'd love to hear about it.
Thanks
I have tried to create a subroutine to merge the two recordsets, so that if the data in the new parts table matches that in the old, the old data gets overwritten, otherwise the data should be added to the old table. Unfortunately I've come up against a brick wall in the form of one of ASPs lovely incomprehensible, and often wildly inaccurate, error messages. I can't figure out where I've gone wrong and I've a feeling my changes to the code are just making things worse at this stage. Below is the sub which, supposedly, merges the recordsets. I know it's probably totally wrong, but it's all I've got. Some of the lines are quite long and may get wrapped in peculiar places.
private sub mergeDB (newdb, olddb)
Dim dbc
dim dbc2
Dim strConn
dim strConn2
dim rs
dim rs2
strConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& olddb
strConn2 = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& newdb
Set dbc = Server.CreateObject("ADODB.Connection"
set dbc2 =server.createobject("adodb.connection"
dbc.open strConn
dbc2.open strConn2
strSQL2="SELECT * FROM parts"
set rs2=server.createobject("adodb.recordset"
rs2.open strSQL2, dbc2, adOpenStatic, adLockReadOnly, adCmdText
while not rs2.eof
strSQL="select * from parts where partno='" & rs2("partno"
set rs=server.createobject("adodb.recordset"
rs.open strSQL, dbc, adOpenKeyset, adLockOptimistic, adCmdText
while not rs.eof
for each i in rs.fields
if rs2.fields(i)<>"" then rs.fields(i)=rs2.fields(i)
next
rs.movenext
wend
if rs.eof then
rs.addnew
for each i in rs.fields
if rs2.fields(i)<>"" then
rs.fields(i)=rs2.fields(i)
else
rs.fields(i)=""
end if
next
rs.update
end if
rs.close
set rs=nothing
rs2.movenext
wend
rs2.close
set rs2=nothing
dbc.close
set dbc=nothing
dbc2.close
set dbc2=nothing
End sub
The error I get when running the above code is:
ADODB.Recordset error '800a0bb9'
The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.
/indespension/Loader.asp, line 248
Line 248 contains the code "rs2.open strSQL2, dbc2, adOpenStatic, adLockReadOnly, adCmdText", which I can't see any problem with.
If anyone can a) see what I've done wrong or b) offer a different solution to this problem I'd love to hear about it.
Thanks