|
 |
access_asp thread: Microsoft JET Database Engine (0x80040E24). Help!!
Message #1 by ajayvarma1@a... on Wed, 28 Nov 2001 17:21:33
|
|
Hello Folks,
I'm really stuck and need help. I have a basic form page that when
submitted goes to a database record add page (called AddPatient.asp).
Upon submit I get the following error from the browser based on the
AddPatient.asp page:
Error Type:
Microsoft JET Database Engine (0x80040E24)
Rowset does not support fetching backward.
/AddPatient.asp, line 55
My database is set-up in MS Access2000. Line 55 of my code is:
objRS.MoveLast ' Moves cursor to last record in recordset.
I'm trying to write to my database using the methods of the Recordset
Object as presented in the Beginning ASP 3.0 book (pp. 595 and 661). My
code is as follows:
<! - - METADATA TYPE= "typelib" FILE="C:\program files\common
files\system\ado\msado15.dll" - ->
<html>
<head>
<title>AddPatient.asp</title>
</head>
<body>
<%
' ******* ASP Variable Declarations **********
Dim objConn ' connection object.
Dim objRS ' recordset object for
PatientInfo table.
Dim adOpenStatic
Dim adLockOptimistic
Dim adCmdTable
adOpenStatic=0
adLockOptimistic = 1
adCmdTable = 2
%>
<%
' Explicitly Creates the ADO Connection and Recordset Objects:
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
' MS-Access Connection String opening to database:
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data
Source=c:\datastores\patients.mdb; " & _
"Persist Security
Info=False"
' Using Connection Object to open the Recordset objects:
' Sequence Order: recordset.Open Source, ActiveConnection, CursorType,
LockType, Options
objRS.Open "PatientInfo", objConn, adOpenStatic, adLockOptimistic,
adCmdTable
%>
<%
objRS.MoveLast ' Moves cursor to last record in recordset.
objRS.AddNew ' Adds a new blank record for Patient
Information to recordset.
' Writes Patient Information details from 1st Table in PatientRegister.asp
form to recordset object's new record:
objRS("SSN") = request.form("SSN")
objRS("lastName") = request.form("lastName")
objRS("firstName") = request.form("firstName")
objRS("middleInitial") = request.form("middleInitial")
objRS("address") = request.form("address")
objRS.Update ' Writes record data to database for
Patient Information.
' Redirects the current user to Confirmation.asp page:
Response.Redirect "PatientConfirmation.asp"
'Closing connection string:
ObjRS.Close
ObjConn.Close
Set ObjRS = Nothing
Set ObjConn = Nothing
%>
Please Help. Thanks.
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 29 Nov 2001 10:31:51 +1100
|
|
You don't need .movelast before you use .addnew
Secondly, Response.Redirect stops execution of the current page - you
should .close and Set = Nothing all your objects *before* you redirect.
Thirdly, because you have the TypeLib reference at the top of your page, you
don't need the following lines:
: Dim adOpenStatic
: Dim adLockOptimistic
: Dim adCmdTable
:
: adOpenStatic=0
: adLockOptimistic = 1
: adCmdTable = 2
These values are already defined in the TypeLib.
Now, do you want to know why you are getting the error?
If you look in adovbs.inc, you'll find that 0 for CursorTypeTnum is actually
adOpenForwardOnly, *not* adOpenStatic. So you're opening an
adOpenForwardOnly cursor. Becuase you assigned the wrong value to your
variable (adOpenStatic), you're not getting the cursor type you expect.
This is one of the reasons that I argue against defining constants inline on
my website
Cheers
Ken
|
|
 |