Private Sub cmdUpdateThroughCursor_Click( _
ByVal eventSender As System.Object, _
ByVal eventArgs As System.EventArgs) _
Handles cmdUpdateThroughCursor.Click
' Declare variables
Dim i As Integer
Dim myConn As New ADODB.Connection
Dim myRS As New ADODB.Recordset
Dim SQLString As String
On Error GoTo HandleError
' Connect
myConn.Provider = "SAOLEDB"
myConn.ConnectionString = _
"Data Source=SQL Anywhere 12 Demo"
myConn.Open()
myConn.BeginTrans()
SQLString = "SELECT * FROM Customers"
myRS.Open(SQLString, myConn, _
ADODB.CursorTypeEnum.adOpenDynamic, _
ADODB.LockTypeEnum.adLockBatchOptimistic)
If myRS.BOF And myRS.EOF Then
MsgBox("Recordset is empty!", 16, "Empty Recordset")
Else
MsgBox("Cursor type: " & CStr(myRS.CursorType), _
MsgBoxStyle.Information)
myRS.MoveFirst()
For i = 1 To 3
MsgBox("Row: " & CStr(myRS.Fields("ID").Value), _
MsgBoxStyle.Information)
If i = 2 Then
myRS.Update("City", "Toronto")
myRS.UpdateBatch()
End If
myRS.MoveNext()
Next i
myRS.Close()
End If
myConn.CommitTrans()
myConn.Close()
Exit Sub
HandleError:
MsgBox(ErrorToString(Err.Number))
Exit Sub
End Sub