Sub inputdate()
Dim strConn As String, strSQL As String
Dim conn As ADODB.Connection
Dim ds As ADODB.Recordset
Dim Str As String
Dim Str1 As String
Dim st As String
Dim i As Integer, j As Integer
Str = "'" & Worksheets("raw").Range("C1").Value & "'"
Str1 = "'" & Worksheets("raw").Range("E1").Value & "'"
'st = Worksheets("sheet1").Range("A2").Value
Worksheets("raw").Range("A3:H200000").Cells.Clear
Set conn = New ADODB.Connection
Set ds = New ADODB.Recordset
'连接数据库的字符串
strConn = "Provider=MSDASQL;Driver={MySQL ODBC 5.3 ANSI Driver};Server=aaaa;Port=33146;Database=oper;uid=dep;Password=******;Data Source Name=ods;"
strSQL = "call qc_ob_memo_match_inputdate(" & Str & "," & Str1 & ");"
'打开数据库连接
conn.Open strConn
With ds
'根据查询语句获得数据
.Open strSQL, conn
'自动控制加入所有列标题
'For col = 0 To ds.Fields.Count - 1
'请注意Offset(0, col)中的参数一定要正确噢
' Worksheets("CS-Outbound").Range("A1").Offset(0, col).Value = ds.Fields(col).Name
'Next
'加入所有行数据
Worksheets("raw").Range("A2").Offset(1, 0).CopyFromRecordset ds
End With
'以下是关闭数据库连接和清空资源
Set ds = Nothing
conn.Close
Set conn = Nothing
End Sub
VBA访问mysql事件
最新推荐文章于 2023-11-26 22:49:35 发布