سلام
خیلی ساده است، این یک نمونه برای اتصال به MySql
ولی بیخود وقتتون رو روی این مورد هدر ندین، حتی اگر سرویس دهنده ای پشتیبانی کنه ممکنه بعدا پشتیبانیش رو قطع کنه و دستتون بمونه تو پوست گردو
With ADO, you can open a connection, open a recordset on that connection, disconnect the recordset from the connection and close the connection. This gives you a recordset that is sitting at the client with no active connection to the server. Connections eat up resources at the server, so depending on the number of users you're going to have, disconnected recordesets can help you service more users with a smaller server. You can use the recordset in a batch mode (as in my example) or you can bind it to a grid or the controls on your form. Changes to your form (and therefore the recordset) only exist at the client. When you're ready to apply the changes to the database (the user clicks the Save button), you open the connection, reconnect the recordset to it and call the .UpdateBatch method to apply all of the changes in the recordset to the database. (FYI - If you have an open recordset that is tied to a connection and you close the connection, the recordset closes too. This is why you MUST disconnect the recordset BEFORE closing the connection.)
Sub Main()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Provider = "MSDASQL"
cn.Properties("Persist Security Info") = True
cn.Properties("Prompt") = adPromptNever
cn.Properties("Password") = "LetMeIn"
cn.Properties("User ID") = "dcaillouet"
cn.Properties("Extended Properties") = "Driver=mysql;server=11.100.255.252;Database=TestD b;Option=1"
cn.Open
strSQL = "Select * from TableX"
rs.ActiveConnection = cn
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockBatchOptimistic
rs.Properties("Update Criteria") = adCriteriaTimeStamp
rs.Properties("Update Resync") = adResyncInserts + adResyncUpdates
rs.Source = strSQL
rs.Open
rs.MarshalOptions = adMarshalModifiedOnly
Set rs.ActiveConnection = Nothing
cn.Close
Do While Not rs.EOF
'Do something with the data here
rs.Fields("FieldNameHere").Value = "Testing 1 2 3"
rs.MoveNext
Loop
cn.Open
Set rs.ActiveConnection = cn
rs.UpdateBatch adAffectAll
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub