To retrieve the information stored in a field, use the Value property of the Fields collection. The following code example shows how to retrieve information from an ADOCE database using the Value property of the Fields collection and the RecordCount property of the Recordset object, then displays the data in 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
You can add a record, change information in an existing record, or remove a record from a database. Before you can modify information in a database, you must change the recordset from its default read-only status to write status. To do this, change the default parameters CursorType and LockType when opening the recordset with the Open method. The following code example shows how to change the recordset to write status.
Dim rs
'Create an ADOCE Recordset object
Set rs = CreateObject("ADOCE.RecordSet")
'Open myTable as a ecordset object with
'write status by specifying a CursorType
'value of 1 and a LockType value of 3.
rs.Open "myTable", "", 1, 3
Once you have set the recordset to write status, you can use the AddNew method to create a new record in a recordset. When used without parameters, the AddNew method creates a record but does not store data in the record. When you use the AddNew method with parameters, the data is stored to the record when the record is created. The following code example shows how to use AddNew with parameters to create a new record and store data in the new record.
'This statement adds the string "Windows CE" to the field "firstfield."
rs.AddNew "firstfield", "Windows CE"
To change a record, rather than add one, make the required changes to the fields and use the Update method. If you use the Update method with parameters, the changes are automatically made to the database. The following code example shows how to use Update.
rs.Update "firstfield", "ADOCE"
You can add a new record to a recordset using the AddNew method with the Update method. After creating the new record using the AddNew method without parameters, add data to the record using the Fields collection and write the data to the database using the Update method. The following code example shows how to use these two methods together to write data to the recordset.
'This statement creates a new record.
rs.AddNew
'These two statements use the fields collection
'to add data to the recordset.
rs.Fields("firstfield") = "Active Data Objects"
rs.Fields("secondfield") = 1.8
'This statement modifies the database
'based on the recordset.
rs.Update
The Delete method removes the current record in the recordset. A deleted record remains current until you move to a different record, after which the deleted record is no longer accessible. The following code example shows how to delete the current record in a recordset and move the pointer to the first record in the recordset.
'This statement deletes the current record.
rs.Delete
'This statement moves the pointer to the
'first record in the recordset
rs.MoveFirst
rs.Update