Sub SQLTest()
Dim connection As New ADODB.connection
Dim recordSet As ADODB.recordSet
Dim searchStr As String
Dim connStr As String
Dim currSheet As Worksheet
connStr = "Provider=SQLOLEDB;Server=127.0.0.1;Database=BMS;Trusted_Connection=yes;Uid=sa;Pwd="
connection.Open connStr
Set currSheet = Workbooks(1).Sheets(2)
Dim sqlStr As String
sqlStr = "SELECT * FROM M_嬈柋僾儔儞"
Set recordSet = New ADODB.recordSet
recordSet.Open sqlStr, connection
Dim i As Integer
i = 1
While Not recordSet.EOF
currSheet.Cells(i, 1).Value = recordSet.Fields(0).Value
currSheet.Cells(i, 2).Value = recordSet.Fields(1).Value
recordSet.MoveNext
i = i + 1
Wend
End Sub
加上
Trusted_Connection=yes
posted on 2010-08-30 15:37
Ying-er 阅读(485)
评论(0) 编辑 收藏 所属分类:
VBA