How do we know the current bookmark is pointing to which record while opening a table?
    When we open a Recordset, we will get a set of     record from the table or the result of the SQL command.
  How can we identify the bookmark that is pointing to     which record (or row)?
    
  The ASP codes are written and described as below:
     
  
    <%
  
Set conn = Server.CreateObject("Adodb.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")
Set rs = Server.CreateObject("Adodb.Recordset")
    rs.open "User",conn,1,3
  
'When a recordset open a table, normally, the bookmark will point to the first record.
    Response.Write(rs.fields(0).value) 'Display     the first record value from first column.
  
%>
    
  But what happen when table does not have any record?
When you use the data in the recordset like <% response.write(rs.fields(0).value) %>, the error will occur:
    
    So, you will need to check it before you use the data     in the 'recordset'.
  The ASP codes are written and described as below:
  
    <%
  
Set conn = Server.CreateObject("Adodb.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")
Set rs = Server.CreateObject("Adodb.Recordset")
rs.open "User",conn,1,3
'When a recordset open a table, normally, the bookmark will point to the first record.
    If NOT rs.EOF Then 'If     the EOF is not true; which means it has some record in the table     when you just opened the table
  
    Response.Write(rs.fields(0).value) 'Display     the first record value from first column
  
End If
rs.Close
    Set rs = Nothing
  
%>
 
No comments:
Post a Comment