Excel VBA:写入mysql数据库

Excel VBA:写入mysql数据库,第1张

Excel VBA:写入mysql数据库

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

''http://support.microsoft.com/kb/246335Set 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 notesstrFile = Workbooks(1).FullNamestrCon = "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 ''DSNNamestrSQL = "INSERT INTO [ODBC;DSN=DSNName;].NameOfMySQLTable " _& "Select AnyField As NameOfMySQLField FROM [Sheet1$];"cn.Execute strSQL


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5062644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存