我想在mysql workbench中动态查询数据库,这取决于我可以在单元格中键入的日期或数字(在vba中)。对于查询它确实以某种方式工作,但如果我使用另一个查询它不起作用,我不知道为什么。你能帮我创建一个能够根据单元格中输入的日期动态地从mysql工作台查询数据的代码。
Sub test()
Dim sSQLQry As String
Dim ReturnArray
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
Dim var As String
Dim ha As String
Dim na As String
DBPath = ThisWorkbook.FullName
ha = "select * from sap.change limit"
var = Sheets("Sheet2").Range("U2").Text
na = ha & " " & var
MsgBox na
Conn.ConnectionString = "..."
Conn.Open
sSQLSting = na
mrs.Open sSQLSting, Conn
Sheet5.Range("A2").CopyFromRecordset mrs
'Close Recordset
mrs.Close
'Close Connection
Conn.Close
End Sub
答案 0 :(得分:0)
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
Dim var As String
Dim ha As String
Dim na As String
DBPath = ThisWorkbook.FullName
ha = "select * from sap.change where id = 100"
Conn.ConnectionString = "..."
Conn.Open
sSQLSting = ha
mrs.Open sSQLSting, Conn
'Close Recordset
mrs.Close
'Close Connection
Conn.Close
End Sub
对于此查询,例如它不起作用。语法有问题吗?