How to edit a record in the RecordSet
S T E P - 1
- We need to create a RecordSet:
<%
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 "SELECT * FROM member WHERE MemberID='" & strMemberID & "';", oConn, adOpenKeyset, adLockPessimistic 'Open "Member"table and found a single record based on the value of strMemberID
%>
S T E P - 2
- We need to check the record if it is existed or not.
- If the RecordCount = 0 , that means the record is not existed in the database:
<%
If oRs.RecordCount = 0 Then
Response.Write("The record is not found")
Response.End
End If
%>
S T E P - 3
- If the RecordCount <> 0 , we continue the edit function:
<%
If oRs.RecordCount = 0 Then
Response.Write("The record is not found")
Response.End
Else
oRs("MemberID") = "Your New ID"
oRs("Password") = "Your New Password"
oRs("Email") = "Your New Email"
End If
%>
S T E P - 4
- Finally, you need to update the table, if not, the new record will not be changed.
<%
If oRs.RecordCount = 0 Then
Response.Write("The record is not found")
Response.End
Else
oRs("MemberID") = "Your New ID"
oRs("Password") = "Your New Password"
oRs("Email") = "Your New Email"
oRs.Update
End If
%>
S T E P - 5
- Dont forget to close the RecordSet and Connection.
<%
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing
%>