Excel VBA:查询MySQL数据库 [英] Excel VBA: Query a MySQL Database
本文介绍了Excel VBA:查询MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找有关如何使用Excel VBA查询MySQL数据库的示例.
I am looking for an example of how to query a MySQL database using Excel VBA.
我能够使用 Data \ From Other Sources \ From Microsoft Query 从数据库中导入数据,但是我真正想要的是一种不将结果直接输出到电子表格之前,直接将其导入到电子表格中,而不是VBA中的数据结构中以进行进一步处理.我该怎么办?
I am able to use Data \ From Other Sources \ From Microsoft Query to import data from the db, but what I am actually looking for is a way not to import it to a spreadsheet directly, but rather to a data structure in VBA for further manipulation before I output the result to the spreadsheet. How can I do this?
推荐答案
进行连接:
conMySQL.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};" & "SERVER=" & server & ";" & " DATABASE=" & database & ";" & "UID=" & login_user & ";PWD=" & password & "; OPTION=3; PORT=" & port & ";Connect Timeout=20;"
'open the connection
conMySQL.Open
然后查询:
strSQL = "SELECT x FROM some_table"
MySQL.Query (strSQL)
With rsTemporary
Do Until .EOF
recordCount = recordCount + 1
some_variable = ![supcode]
rsTemporary.MoveNext
Loop
End With
MySQL.closeCon
这篇关于Excel VBA:查询MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文