文章摘要:excel连接mysql失败怎么办 Excel不能连接mysql
excel连接mysql失败的解决方法 当excel连接mysql失败时可以在excel中添加以下代码即可连接 […]
excel连接mysql失败的解决方法
当excel连接mysql失败时可以在excel中添加以下代码即可连接到MySQL。
Public Sub nckxr()
Dim cnn As ADODB.ConnectionDim cnnstr As String, mydata As String
mydata = "nckxr" '指定数据库名称
cnnstr = "providet=SQLoledb;" _
& "user id=sa;" _
& "password=111;" _
& "date source=ZBS3;" _
& "initial catalog=" & mydata
set cnn = new ADODB.Connectioncnn.connectionstring = cnnstr
On Error Resume Next
cnn.Open
On Error GoTo 0
If cnn.State = adstateopen Then
MsgBox "数据库连接成功!", vbInformation, "连接数据库"
Else
MsgBox "数据库连接失败!", vbInformation, "连接数据库"
End If
Set cnn = Nothing
End Sub