How to find a record by using RecordSet
S T E P - 1
- We need to create a RecordSet and Connection.
<%
Const adOpenKeyset = 1, adLockPessimistic = 2
Dim oConn
Dim oRs
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")
Set oRs = Server.CreateObject("ADODB.Recordset")
oRs.Open "Member", oConn, adOpenKeyset, adLockPessimistic 'Open "Member"table
%>
S T E P - 2
- We use Find method to search a record:
<%
oRs.Find "MemberID='YourID'", 0, adSearchForward
'Search a record that the member id is 'YourID', and search form first record.
If oRs.EOF Then 'If the EOF is TRUE, that means the record not found
Response.write "Record not found"
Else
Response.write oRs("Email")
End If
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = nothing
%>
No comments:
Post a Comment