您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Excel VBA:写入mysql数据库

Excel VBA:写入mysql数据库

您可以使用连接字符串和ADO连接到MysqL

''http://support.microsoft.com/kb/246335
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

strCon = "Driver={MysqL ODBC 3.51 Driver};Server=localhost;Database=MyDB;" _
& "User=root;Password=pw;Option=3;"

cn.Open strCon

您还可以使用Jet驱动程序将DSN与Excel连接使用:

Dim cn As ADODB.Connection

''Not the best way to get the name, just convenient for notes
strFile = Workbooks(1).FullName
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
    & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

Set cn = CreateObject("ADODB.Connection")

''For this to work, you must create a DSN and use the name in place of 
''DSNName
strsql = "INSERT INTO [ODBC;DSN=DSNName;].NameOfMysqLTable " _
& "Select AnyField As NameOfMysqLField FROM [Sheet1$];"

cn.Execute strsql
MySQL 2022/1/1 18:23:49 有616人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶