Konst_One писал(а):или я чего то не помню, алибек просвяти пжл по данному вопросу (ассинхронность в акцессе)
'BeginAppendChunkVB
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
Public Sub AppendChunkX()
'recordset and connection variables
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim rstPubInfo As ADODB.Recordset
Dim strSQLPubInfo As String
'record variables
Dim strPubID As String
Dim strPRInfo As String
Dim lngOffset As Long
Dim lngLogoSize As Long
Dim varLogo As Variant
Dim varChunk As Variant
Dim strMsg As String
Const conChunkSize = 100
' Open a connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
Cnxn.Open strCnxn
' Open the pub_info table with a cursor that allows updates
Set rstPubInfo = New ADODB.Recordset
strSQLPubInfo = "pub_info"
rstPubInfo.Open strSQLPubInfo, Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable
' Prompt for a logo to copy
strMsg = "Available logos are : " & vbCr & vbCr
Do While Not rstPubInfo.EOF
strMsg = strMsg & rstPubInfo!pub_id & vbCr & _
Left(rstPubInfo!pr_info, InStr(rstPubInfo!pr_info, ",") - 1) & _
vbCr & vbCr
rstPubInfo.MoveNext
Loop
strMsg = strMsg & "Enter the ID of a logo to copy:"
strPubID = InputBox(strMsg)
' Copy the logo to a variable in chunks
rstPubInfo.Filter = "pub_id = '" & strPubID & "'"
lngLogoSize = rstPubInfo!logo.ActualSize
Do While lngOffset < lngLogoSize
varChunk = rstPubInfo!logo.GetChunk(conChunkSize)
varLogo = varLogo & varChunk
lngOffset = lngOffset + conChunkSize
Loop
' Get data from the user
strPubID = Trim(InputBox("Enter a new pub ID" & _
" [must be > 9899 & < 9999]:"))
strPRInfo = Trim(InputBox("Enter descriptive text:"))
' Add the new publisher to the publishers table to avoid
' getting an error due to foreign key constraint
Cnxn.Execute "INSERT publishers(pub_id, pub_name) VALUES('" & _
strPubID & "','Your Test Publisher')"
' Add a new record, copying the logo in chunks
rstPubInfo.AddNew
rstPubInfo!pub_id = strPubID
rstPubInfo!pr_info = strPRInfo
lngOffset = 0 ' Reset offset
Do While lngOffset < lngLogoSize
varChunk = LeftB(RightB(varLogo, lngLogoSize - lngOffset), _
conChunkSize)
rstPubInfo!logo.AppendChunk varChunk
lngOffset = lngOffset + conChunkSize
Loop
rstPubInfo.Update
' Show the newly added data
MsgBox "New record: " & rstPubInfo!pub_id & vbCr & _
"Description: " & rstPubInfo!pr_info & vbCr & _
"Logo size: " & rstPubInfo!logo.ActualSize
' Delete new records because this is a demo
rstPubInfo.Requery
Cnxn.Execute "DELETE FROM pub_info " & _
"WHERE pub_id = '" & strPubID & "'"
Cnxn.Execute "DELETE FROM publishers " & _
"WHERE pub_id = '" & strPubID & "'"
' clean up
rstPubInfo.Close
Cnxn.Close
Set rstPubInfo = Nothing
Set Cnxn = Nothing
End Sub
'EndAppendChunkVB
Option Explicit
Dim WithEvents c As ADODB.Connection
Dim WithEvents r As ADODB.Recordset
Private Sub c_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
List1.AddItem "Connection_ConnectComplete"
End Sub
Private Sub c_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
List1.AddItem "Connection_ExecuteComplete"
List1.AddItem "First item: " & pRecordset.Fields(0).Value
List1.AddItem "RecordCount: " & pRecordset.RecordCount
End Sub
Private Sub Form_Click()
Debug.Print r.Fields(0)
r.MoveNext
End Sub
Private Sub Form_Load()
Set c = New ADODB.Connection
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WORK\VBProgs\Totalizator\tdata.mdb"
Set r = New ADODB.Recordset
Set r.ActiveConnection = c
r.CursorLocation = adUseClient
List1.AddItem "* Prepared"
r.Open Source:="select * from [KLADR-ADR]", Options:=ADODB.ExecuteOptionEnum.adAsyncExecute Or ADODB.ExecuteOptionEnum.adAsyncFetchNonBlocking
List1.AddItem "* Executed"
End Sub
Private Sub r_FetchComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
List1.AddItem "Recordset_FetchComplete"
End Sub
Private Sub r_FetchProgress(ByVal Progress As Long, ByVal MaxProgress As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
List1.AddItem "Recordset_FetchProgress" & " (" & Progress & "/" & MaxProgress & ")"
End Sub
Options:=ADODB.ExecuteOptionEnum.adAsyncExecute Or ADODB.ExecuteOptionEnum.adAsyncFetchNonBlocking
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1