BOF-EOF
am 12.04.2007 02:14:41 von rn5aConsider the following code which retrieves records from a MS-Access
database table:
<%
Dim objConn
Set objConn=Server.CreateObject("ADODB.CONNECTION")
'open connection using ConnectionString
Dim strSQL1
strSQL1="SELECT......"
Dim objRS1
Set objRS1=Server.CreateObject("ADODB.RECORDSET")
objRS1.Open strSQL1,objConn,adOpenKeyset
If Not(objRS1.EOF)
Response.Write(objRS1("Col1"))
Else
Dim strSQL2
strSQL2="SELECT....."
Dim objRS2
Set objRS2=Server.CreateObject("ADODB.RECORDSET")
objRS2.Open strSQL2,objConn
Response.Write(objRS2("Col1"))
objRS2.Close
Set objRS2=Nothing
End If
Response.Write(objRS1("Col2"))
%>
Note that both the SQL queries will retrieve only ONE record. Now when
I execute the above code, ASP generates the
Exception occured.
error without pointing to any line. What could be the cause of the
error? I guess it could be because of the last Response.Write line
which spits out the value of objRS1("Col2") but I don't understand
what could be the reason for the last Response.Write line to generate
the above error.
If I add the following line
objRS1.MoveFirst
immediately after the End If line & just before the last
Response.Write line, then the error changes to
Either BOF or EOF is True, or the current record has been deleted.
Requested operation requires a current record.
pointing to the objRS1.MoveFirst line. Can someone please point out
what's wrong with the above code?