Ok, nu har jeg kigget lidt på det.
Først og fremmest skal mysql-server tillade forbindelse udefra, og du skal kunne komme i kontakt med den gennem deres firewall.
Private Function ConnectString() As String
Dim strServerName As String
Dim strDatabaseName As String
Dim strUserName As String
Dim strPassword As String
'Change to IP Address if not on local machine
'Make sure that you give permission to log into the
'server from this address
'See Adding New User Accounts to MySQL
'Make sure that you d/l and install the MySQL Connector/ODBC 3.51 Driver
strServerName = "din mytsql ip"
strDatabaseName = "din mysql databse"
strUserName = "din mysql brugernavn"
strPassword = "din mysql brugernavn password"
ConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & strServerName & _
";DATABASE=" & strDatabaseName & ";" & _
"USER=" & strUserName & _
";PASSWORD=" & strPassword & _
";OPTION=3;"
End Function
Function Sql(strSQL As String)
On Error GoTo Sql_Error
Dim b As Long
'MsgBox strSQL
Set cn = CreateObject("ADODB.Connection")
Me.MousePointer = 11
cn.Open ConnectString()
With cn
.CommandTimeout = 0
End With
Set Rs = CreateObject("ADODB.RecordSet") 'Creates record set
Rs.Open strSQL, cn
List1.Clear
List2.Clear
If Rs.EOF Then
GoTo ExitSub
Else
Do
'<do whatever you need to do with the data here>
'eks. List1.AddItem Rs(2)
Rs.MoveNext
Loop While Not Rs.EOF
End If
ExitSub:
Rs.Close
Set Rs = Nothing
cn.Close
Set cn = Nothing
On Error GoTo 0
Me.MousePointer = 0
Exit Function
Me.MousePointer = 0
Sql_Error:
If Not Err.Number = 3704 Then '3704 intet dat resultat
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command1_Click of Form " & Me.Name
End If
Me.MousePointer = 0
End Function
Funtion SQl er den der udføre sql ordren,
Private Function ConnectString opretter forbindelsen til mysql serveren, husk at ændre den function så oplysningerne passer.
Sql ("SELECT * FROM lan ORDER BY id ASC")
Nu kan du eksevere ganske almindelig sql ordre.
og husk at installere mysql-obdc driver hvis du ikke allerede har.
http://dev.mysql.com/get/Downloads/MyODBC3/mysql-connector-odbc-3.51.12-win32.zip/from/pick#mirrorshttp://dev.mysql.com/doc/refman/5.0/en/dsn-on-windows.html?ff=nopfpls-Thomas
Indlæg senest redigeret d. 15.05.2006 13:05 af Bruger #65