Resync メソッドの例 (VB)

この例では、Resync メソッドを使って、静的レコードセット内のデータを更新します。

Public Sub ResyncX()

    Dim strCnn As String
    Dim rstTitles As ADODB.Recordset

    ' Open connections.
        strCnn = "Provider=sqloledb;" & _
        "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "

    ' Open recordset for Titles table.
    Set rstTitles = New ADODB.Recordset
    rstTitles.CursorType = adOpenKeyset
    rstTitles.LockType = adLockBatchOptimistic
    rstTitles.Open "Titles", strCnn, , , adCmdTable

    ' Change the type of the first title in the recordset.
    rstTitles!Type = "database"

    ' Display the results of the change.
    MsgBox "Before resync: " & vbCr & vbCr & _
        "Title - " & rstTitles!Title & vbCr & _
        "Type - " & rstTitles!Type

    ' Resync with database and redisplay results.
    rstTitles.Resync
    MsgBox "After resync: " & vbCr & vbCr & _
        "Title - " & rstTitles!Title & vbCr & _
        "Type - " & rstTitles!Type

    rstTitles.CancelBatch
    rstTitles.Close

End Sub