Friday, December 14, 2007

How to modify the current record?

How to modify the current record?

When we open a Recordset and point to a record, we can modify that record by using Update method.


The ASP codes are written and described as below:

<%

Const adSearchBackward = 1

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 "Member",conn,1,3

if Not rs.EOF Then

rs.MoveFirst 'Move to the first record;

rs.Find "Location = 'LA'" 'Find the first record that the location is "LA"

If rs.EOF Then 'If EOF is True; which means the record is not found!

Response.write("Record Not Found!
")

Else

rs.Update "Location", "UK" 'After we found the record, we change the location to the "UK"

End If

End IF

rs.Close

Set rs = Nothing

%>


We can also modify more than one column at the same time, and update all:

<%

rs.fields("MemberName") = "Ally McBeal"

rs.fields("Location") = "UK"

rs.Update 'We need to use Update method

%>

No comments: