MDAC 2.5 SDK - OLE DB Providers
Cursor Service for OLE DB
Using the Cursor Service, you can make any changes to the local data: modify data fields, delete existing rows, and insert new rows into the rowset. The changes are immediately committed to the cache and are visible from all the cloned Recordset objects on that rowset. Local changes can be committed to the data provider row by row or once for the entire rowset. The built-in synchronization functionality handles the commit process.
Additionally, committing changes to the rowset while "disconnected" will clear pending update flags and the row will be treated as having no pending changes. This is useful in cases where the consumer is sending updates manually and wants to mark a row as having been committed to the provider.
The following code sample shows a way to make modifications to a disconnected Recordset object and then commit those changes to the database:
Private Sub ShowUpd_Click()
Dim rs As New adodb.Recordset
Dim cn As New adodb.Connection
' Open recordset with client-side cursors
Cn.open "provider=sqloledb;server=dbsrv1;database=pubs;uid=sa;pwd=;"
rs.CursorLocation = adUseClient
rs.Open "select * from jobs", cn, adOpenStatic, adLockBatchOptimistic
' Close connection–-leave the disconnected recordset open
cn.close
set cn = nothing
' Update records
rs.MoveFirst
rs("job_desc") = "PM"
rs.MoveNext
rs("job_desc") = "CEO"
' Commit changes locally in recordset buffer
rs.UpdateBatch
' Make more changes
rs.MoveNext
rs.Delete
rs.MoveLast
rs.Delete
rs.AddNew
rs("job_id") = 16
rs("job_desc") = "STE"
rs("min_lvl") = 9
rs.Update
rs.MoveFirst
rs("job_desc") = "WB"
' Reconnect recordset
cn.Open "provider=sqloledb;server=dbsrv1;database=pubs;uid=sa;pwd=;"
Set rs.ActiveConnection = cn
' Submit changes to datasource-–only latest changes will be saved
rs.UpdateBatch
Set rs = Nothing
Set cn = Nothing
End Sub