Monday, December 17, 2007

How to create a RecordSet

How to create a RecordSet

S T E P - 1

- First, we need a connection.

Dim oConn

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb")

S T E P - 2

- We can use a SQL command to search the information in a database, and create it to a RecordSet.

Dim oRs

Set oRs = oConn.Execute("SELECT * FROM Member")

S T E P - 3

- We also can use the Server.CreateObject to create a RecordSet directly.

Dim oRs

Set oRs = Server.CreateObject("ADODB.Recordset")

oRs.Open "Member", oConn, , , adComdTable 'Open "Member"table

S T E P - 4

- After finished using the RecordSet, we will need to close it:

oRs.Close

Set oRs = Nothing

No comments: