|
在EXCEL泡了好久,终于会用了点ADO,今天就来秀一下用ADO操作MYSQL数据库,欢迎大家一起讨论
VBE中请确定引用 microsoft activeX data objects xx 库
连接及更新MYSQL数据库数据 代码如下:
Sub updt()
Dim strconnt As String
strconnt = ""
Set connt = New ADODB.Connection
Dim sevip, Db, user, pwd As String
'设服务器地址、所连数据,及登录用户密码
sevip = "localhost" '"192.168.*.*"
Db = "samp_db"
user = "root"
pwd = "6901205"
strconnt = "DRIVER={MySql ODBC 3.51 Driver};SERVER=" & sevip & ";Database=" & Db & ";Uid=" & user & ";Pwd=" & pwd & ";Stmt=set names GBK" '
connt.ConnectionString = strconnt
connt.Open
ssql = "UPDATE student SET student.name= 'kookboy' where student.name = 'kook'"
connt.Execute ssql
MsgBox "成功更新记录!"
connt.Close
Set connt = Nothing
End Sub
按F5执行,执行前中后 界面如下
[注]VBA操作MYSQL的代码在网上找了好多地方也没找到,最后还是在EH找到了,哈哈
参照http://club.excelhome.net/viewthread.php?tid=401099
感谢老前辈分享 |
|