给个例子工程引用ADO Option ExplicitConst ServerIP = "10.168.188.100" '服务器IP Const User = "sa" '用户 Const Pwd = "1223pass" '密码Private Sub Command1_Click() Dim cnn As New ADODB.Connection Dim rst As ADODB.Recordset cnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=Northwind;Data Source=" & ServerIP, User, Pwd Set rst = cnn.Execute("select top 1 shipname from Northwind..orders where CustomerID = 'VINET'") Debug.Print rst(0) '结果输出 End Sub
Option ExplicitConst ServerIP = "10.168.188.100" '服务器IP
Const User = "sa" '用户
Const Pwd = "1223pass" '密码Private Sub Command1_Click()
Dim cnn As New ADODB.Connection
Dim rst As ADODB.Recordset
cnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=Northwind;Data Source=" & ServerIP, User, Pwd
Set rst = cnn.Execute("select top 1 shipname from Northwind..orders where CustomerID = 'VINET'")
Debug.Print rst(0) '结果输出
End Sub