Storing and Retrieving Information

To add, remove, or change information in a database, you must change the default CursorType and LockType when opening the recordset. The following code example shows how to store information in a database.

Dim rs
Set rs = CreateObject("ADOCE.RecordSet")
rs.open "mytable", "", 1, 3
rs. Addnew
rs.fields("firstfield") = "ActiveX Data Objects"
rs.fields("secondfield") = 1.8
rs.Update
rs.Close
Set rs = Nothing

If you use the AddNew method with parameters, you do not need to use the Update method because the changes are automatically made to the database. The following code example shows how to use AddNew.

rs.Addnew "firstfield", "Windows CE"

To change a record, rather than add one, make the required changes to the fields and then use the Update method. If you use Update with parameters, the changes are automatically made to the database. The following code example shows how to use Update.

rs.Update "firstfield", "ADOCE"

After you store data in the database using AddNew and Update, you can use the Value property to get the information stored in a field. The following code example shows how to retrieve information from an ADOCE database. It requires a ListBox named List1.

Dim rs
Set rs = CreateObject("ADOCE.RecordSet")
rs.open "mytable", "", 1, 3
If rs.RecordCount > 0 Then
  Do While Not rs.EOF
    List1.Additem rs.Fields("firstfield").Value
    rs.MoveNext
  Loop
End If
rs.Close
set rs = Nothing