ADO+查询数据库
作者:互联网
Sub 查询数据库()
Set rs = CreateObject("ADODB.RECORDSET")
cnn.Open = "DSN=GSM;uid=ailxl;pwd=ailxl;Database=感知数据库;" 'TABLE=DBO.DATA;"
Sql = "SELECT * FROM [Data] DATA WHERE YEAR([Datetime Id(GSM_CELL)])=2018 "
Set rs = cnn.Execute(Sql) '
Sheets("SHEET2").Cells.ClearContents '清理保存数据的区域
For i = 0 To rs.Fields.Count - 1
Worksheets("SHEET2").Cells(1, i + 1) = rs.Fields(i).Name
Next
Sheets("SHEET2").Range("a2").CopyFromRecordset rs
rs.Close
Set rs= Nothing
end SUB()
标签:Set,rs,DATA,查询数据库,SHEET2,ADO,GSM 来源: https://blog.csdn.net/qq_44390640/article/details/97099843