以SQLSERVER为例
Dim strTemp As String
Dim adoRs As New ADODB.Recordset
Dim adoConn As New ADODB.Connection
strTemp=strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=连接的数据库名;Data Source=连接的计算机名"
adoconn.open strTemp, "用户名", "密码"
set adoRs=nothing
strTemp="select * from 表名"
adoRs.open strtemp,adoconn
if adors.eof or adors.bof then
msgbox "数据库中无记录"
end if