现在数据库建立新库用于存放数据(导航猫或visual studio)
定义链接
Dim a As New ADODB.Connection
Dim rs As New ADODB.Recordset
打开连接
a.ConnectionString = "Provider=SQLOLEDB;Password=sas;Persist Security Info=False;User ID=sa;Initial Catalog=Department_DB;Data Source=192.168.aa,aaa"
a.Open
If rs.State <> adStateClosed Then
rs.Close
End If
rs.Open SQL, hg, adOpenKeyset, adLockPessimistic
ans = rs.GetRows
hang = rs.RecordCount
lie = 9
With ActiveSheet
For i = 0 To hang - 1
For j = 0 To lie - 1
.Cells(i + 2, j + 1).Value = ans(j, i)
Next
Next
End With