Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connection
Dim strCnn As String
'Provider是提供者,sqloledb表明是指向SQL数据库,Data Source是数据源,srv是SQL中的数据库。
strCnn = "rovider=sqloledb;" & _
"Data Source=srv;Initial Catalog=Pubs;User Id=saassword=; "
cnn1.Open strCnn
Dim rstAuthors As ADODB.Recordset
Set rstAuthors = New ADODB.Recordset
'Authors是SQL数据库中的一个表。
rstAuthors.Open "Authors", strCnn, , , adCmdTable
Debug.Print rstAuthors.RecordCount
rstAuthors.Close
cnn1.Close