alex_wareing
asked on
Simple Update code
I'm having trouble with some update code, heres my code:
-------------------------- ---------- ---------- --
'Open the connection the backend DB
DIM objConn
Set objConn = Server.CreateObject("ADODB .Connectio n")
objConn.ConnectionString = MM_RMbackend_STRING
objConn.Open
'Open the table where the records are to be inserted using the key passed from the form
DIM getAppt, Query1, FormKeyVar
FormKeyVar = Request.Form("AppointmentI D")
Set getAppt = Server.CreateObject("ADODB .Recordset ")
Query1 = "SELECT * FROM Appointments WHERE AppointmentID = " + Replace(FormKeyVar, "'", "''") + ""
getAppt.Open Query1, objConn, , adLockOptimistic, adCmdTable
Const AdOpenDynamic = 1
Const adCmdText = 1
Const adLockOptimistic = 3
'check if last app within 90 days of new app
dim lastAppDate, thisAppDate, statBook
If getOtherApps.EOF And getOtherApps.BOF Then
lastAppDate = #01/01/01#
thisAppDate = (getAppt.Fields.Item("Appo intmentDat e").Value)
else
lastAppDate = #01/05/05#
thisAppDate = (getAppt.Fields.Item("Appo intmentDat e").Value)
end if
If DateDiff("d", lastAppDate, thisAppDate) >= 90 Then
'Update the selected record
getAppt("AppointmentRep") = Request.Form("RepID")
getAppt("AppointmentSubjec t") = Request.Form("AppointmentS ubject")
getAppt("Booked") = 1
getAppt.Update
end if
--------------------
When i run the page i get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
Query-based update failed because the row to update could not be found.
/repeatprescribe/regenthou se/repbook 2.asp, line 94 [this is the getAppt.Update line]
When i run the SQL query Query1 it returns the record. whats wring with my code.
--------------------------
'Open the connection the backend DB
DIM objConn
Set objConn = Server.CreateObject("ADODB
objConn.ConnectionString = MM_RMbackend_STRING
objConn.Open
'Open the table where the records are to be inserted using the key passed from the form
DIM getAppt, Query1, FormKeyVar
FormKeyVar = Request.Form("AppointmentI
Set getAppt = Server.CreateObject("ADODB
Query1 = "SELECT * FROM Appointments WHERE AppointmentID = " + Replace(FormKeyVar, "'", "''") + ""
getAppt.Open Query1, objConn, , adLockOptimistic, adCmdTable
Const AdOpenDynamic = 1
Const adCmdText = 1
Const adLockOptimistic = 3
'check if last app within 90 days of new app
dim lastAppDate, thisAppDate, statBook
If getOtherApps.EOF And getOtherApps.BOF Then
lastAppDate = #01/01/01#
thisAppDate = (getAppt.Fields.Item("Appo
else
lastAppDate = #01/05/05#
thisAppDate = (getAppt.Fields.Item("Appo
end if
If DateDiff("d", lastAppDate, thisAppDate) >= 90 Then
'Update the selected record
getAppt("AppointmentRep") = Request.Form("RepID")
getAppt("AppointmentSubjec
getAppt("Booked") = 1
getAppt.Update
end if
--------------------
When i run the page i get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
Query-based update failed because the row to update could not be found.
/repeatprescribe/regenthou
When i run the SQL query Query1 it returns the record. whats wring with my code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you are assinging
Const AdOpenDynamic = 1
Const adCmdText = 1
Const adLockOptimistic = 3
after opening the recordset
Const AdOpenDynamic = 1
Const adCmdText = 1
Const adLockOptimistic = 3
after opening the recordset
ASKER
Works great, is there any chance you could explain this problem a little more
I usually use
getAppt.Open Query1, objConn, 3, 3 ------- for inserting, updating, deleting
getAppt.Open Query1, objConn, 1, 1 ------- i open it just for reading
3,3 or 1,1, defines the recordset object for read/write and movenext/moveprev/requery etc..
hope this makes a sense :)
regards,
Nurbek
getAppt.Open Query1, objConn, 3, 3 ------- for inserting, updating, deleting
getAppt.Open Query1, objConn, 1, 1 ------- i open it just for reading
3,3 or 1,1, defines the recordset object for read/write and movenext/moveprev/requery etc..
hope this makes a sense :)
regards,
Nurbek
If getOtherApps.EOF And getOtherApps.BOF Then
lastAppDate = #01/01/01#
thisAppDate = (getAppt.Fields.Item("Appo
else
lastAppDate = #01/05/05#
thisAppDate = (getAppt.Fields.Item("Appo
end if
To
If getOtherApps.EOF OR getOtherApps.BOF Then
lastAppDate = #01/01/01#
thisAppDate = (getAppt.Fields.Item("Appo
else
lastAppDate = #01/05/05#
thisAppDate = (getAppt.Fields.Item("Appo
end if
why not use a update statement directly?
best regards,
Xiong