Per prima cosa installa questo
http://www.marianoingaldo.it/codeupl...-connector.msi
Di seguito le routine che ti servono
Per la connessione al DB
Public Function Connection() As Boolean
On Error GoTo Exit_Err
Dim PtrMsg As Variant
Dim IsError As Boolean
IsError = True
Set my_db_connection = New ADODB.Connection
my_ConnectionString = "Provider=MSDASQL.1;Password=;Persist Security Info=True;User ID=;Extended Properties=" & Chr$(34) & "DRIVER={MySQL ODBC 3.51 Driver};DESC=;DATABASE=" & db_name & ";SERVER=" & db_server & ";UID=" & db_user & ";PASSWORD=" & db_pass & ";PORT=" & db_port & ";OPTION=16387;STMT=;" & Chr$(34)
my_db_connection.Open my_ConnectionString
IsError = False
Exit_Err:
If IsError Then
PtrMsg = MsgBox("Connessione fallita con il db MySQL ", vbCritical, "Errore fatale sulla connessione al database.")
Connection = False
Exit Function
End If
Connection = True
End Function
Per eseguire una query qualunque
Public Function LoadQuery(Query As String, Rs As ADODB.Recordset) As Boolean //Esecuzione query
On Error GoTo Exit_Err
Dim PtrMsg As Variant
Dim IsError As Boolean
IsError = False
Set Rs = New ADODB.Recordset
Rs.Open Query, my_db_connection
IsError = True
Exit_Err:
If Not IsError Then
LoadQuery = False
End If
LoadQuery = IsError
End Function

Rispondi quotando