|
excel环境:2010版;windos系统:win10 64位
代码如下:
Public Sub insertDB()
Dim Con As ADODB.Connection
Dim Rec As ADODB.Recordset
Dim iRowscount As Long
Set Con = New ADODB.Connection
Con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};" + _
"Server=localhost;" + _
"DataBase=estimate;" + _
"UID=root;" + _
"PWD=root;" + _
"OPTION=3;" + _
"Stmt=Set Names 'GBK';"
Con.Open
Set Rec = New Recordset
Set Rec = Con.Execute("SELECT products_id FROM trn_temp_orders where orders_id in (select max(orders_id) from trn_temp_orders) GROUP BY products_id ", iRowscount, adCmdText)
Range("a1").CopyFromRecordset Rec '在Excel中打印出查询结果
Rec.Close: Set Rec = Nothing
Con.Close: Set Con = Nothing
End Sub
|
|