PDA

View Full Version : Update record ADODB.Recordset (0x800A0BCD) error


ash1984
05-10-2006, 01:53 PM
Hi

Bit of a noob when it comes to asp so any help is very much apreciated.
Keep getting a ADODB.Recordset (0x800A0BCD) BOf or EOF error when trying to update an access database via sql.
below is my code, please help.

<% @ LANGUAGE = VBScript %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
</head>

<body>

<% 'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsUpdateEntry 'Holds the recordset for the record to be updated
Dim strSQL 'Holds the SQL query to query the database
Dim lngRecordNo 'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("Employee_ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Employee.mdb")

'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=Employee"

'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblEmployee.* FROM tblEmployee WHERE Employee_ID=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3

'Open the recordset with the SQL query
rsUpdateEntry.Open strSQL, adoCon

'Update the record in the recordset
rsUpdateEntry.Fields("Name") = Request.Form("Name")
rsUpdateEntry.Fields("HouseNoName") = Request.Form("HouseNoName")
rsUpdateEntry.Fields("StreetAddress") = Request.Form("StreetAddress")
rsUpdateEntry.Fields("CityTown") = Request.Form("CityTown")
rsUpdateEntry.Fields("County") = Request.Form("County")
rsUpdateEntry.Fields("PostCodeOut") = Request.Form("PostCodeOut")
rsUpdateEntry.Fields("PostCodeIn") = Request.Form("PostCodeIn")
rsUpdateEntry.Fields("Age") = Request.Form("Age")
rsUpdateEntry.Fields("PhoneNo") = Request.Form("PhoneNo")
rsUpdateEntry.Fields("DateOfBirth") = Request.Form("DateOfBirth")
rsUpdateEntry.Fields("Email") = Request.Form("Email")

'Write the updated recordset to the database
rsUpdateEntry.Update

'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing

'Return to the update select page in case another record needs deleting
Response.Redirect "update_select.asp"
%>

</body>
</html>

miranda
05-12-2006, 03:34 PM
You need to test for EOF to see if the record exists. Add this line
If Not rsUpdateEntry.EOF Then

this gets placed below this line
rsUpdateEntry.Open strSQL, adoCon


Remember to close the If statement.

If you think that there should be a record in the table then you need to check your sql statement do that by doing the following and place it above the line used to open the recordset object, and below the line where you assign a value to the variable strSQL

Response.Write strSQL