標題:
[分享]
使用ADO查詢DataBase
[打印本頁]
作者:
Min
時間:
2010-6-29 22:16
標題:
使用ADO查詢DataBase
本帖最後由 Min 於 2010-6-29 22:20 編輯
需引用 Microsoft ActiveX Data Objects 2.5 Library 及以上版本
Sub ADO_QueryTable()
Dim Cnnl As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim SQL As String
Dim lCol As Long
Dim lRow As Long
Cnnl.Open "Driver={MySQL ODBC 3.51 Driver};Server=TEST;Port=3306;Database=TEST;CharSet=big5;Uid=TEST;Pwd=TEST;Option=16387" '連接System
SQL = "SELECT COL0,COL1,COL2,COL3,COL4,COL5 FROM TABLE"
Rst.Open SQL, Cnnl, adOpenKeyset, adLockOptimistic
Do Until Rst.EOF
For lCol = 0 To Rst.Fields.Count - 1
Cells(lRow, lCol + 1).Value = Rst(lCol)
Next
lRow = lRow + 1
Rst.MoveNext
Loop
Set Cnnl = Nothing
Set Rst = Nothing
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)