Resync 메서드 예제(VB)
이 예제에서는 Resync 메서드를 사용하여 정적 레코드 집합의 데이터를 새로 고치는 방법을 보여 줍니다.
'BeginResyncVB
'To integrate this code
'replace the data source and initial catalog values
'in the connection strings
Public Sub Main()
On Error GoTo ErrorHandler
'connection and recordset variables
Dim Cnxn As ADODB.Connection
Dim rstTitles As ADODB.Recordset
Dim strCnxn As String
Dim strSQLTitles As String
' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Cnxn.Open strCnxn
' Open recordset using object refs to set properties
' that allow for updates to the database
Set rstTitles = New ADODB.Recordset
Set rstTitles.ActiveConnection = Cnxn
rstTitles.CursorType = adOpenKeyset
rstTitles.LockType = adLockOptimistic
strSQLTitles = "titles"
rstTitles.Open strSQLTitles
'rstTitles.Open strSQLTitles, Cnxn, adOpenKeyset, adLockPessimistic, adCmdTable
'the above line of code passes the same refs as the object refs listed above
' 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
' clean up
rstTitles.CancelBatch
rstTitles.Close
Cnxn.Close
Set rstTitles = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
' clean up
If Not rstTitles Is Nothing Then
If rstTitles.State = adStateOpen Then
rstTitles.CancelBatch
rstTitles.Close
End If
End If
Set rstTitles = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'EndResyncVB
참고 항목
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기