我在旧计算机上运行MySQL服务器,并尝试从当前计算机连接它。我想从Excel访问服务器,但我不断收到错误消息:
'[[Microsoft] [ODBC驱动程序管理器]数据源名称未找到,未指定默认驱动程序'
我已经下载了“ MySQL连接器ODBC 8.0.20 win 32”,它应该符合我的计算机要求。在这一点上,我仍然很不清楚为什么我会不断出错。请在下面找到我的VBA代码。
Private Sub Data_to_SQL_Click()
Dim con As ADODB.Connection
Set con = New ADODB.Connection
Dim strConn As String
strConn = "Driver={MySQL ODCB 8.0 Unicode Driver};SERVER=(my old computer ip address);DATABASE=Database;USER=root;PASSWORD=(password)"
con.Open strConn
Dim rng As Range
Set rng = Application.Range("A2:E14")
Dim row As Range
For Each row In rng.Rowss
Dim Sql As String
Sql = "insert into kavijamaarat (pvm, ravintola, ruoka, hinta, kpl) values ('" & row.Cells(1).Value & "', '" & row.Cells(2).Value & "', '" & row.Cells(3).Value & "', '" & row.Cells(4).Value & "', '" & row.Cells(5).Value & "')"
con.Execute Sql
Next row
con.Close
MsgBox "Done"
结束子
重写
strConn = "Driver={MySQL ODCB 8.0 Unicode Driver};SERVER=(my old computer ip address);DATABASE=Database;USER=root;PASSWORD=(password)"
到
strConn = "Driver={MySQL ODBC 8.0 Unicode Driver};SERVER=(my old computer ip address);DATABASE=Database;USER=root;PASSWORD=(password)"