'先添加引用ado
Dim dbConn As ADODB.Connection
Dim Rst As ADODB.Recordset
Dim conString As String
conString = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=Northwind;User Id =sa;Password=coffee"
Set dbConn = New ADODB.Connection
dbConn.Open conString
Set Rst = New ADODB.Recordset
Rst.CursorLocation = adUseClient
Rst.Open "select * from orders", dbConn, adOpenKeyset, adLockPessimistic, adCmdText
Text1.Text = Rst.Fields("OrderID").Value
Text2.Text = Rst.Fields("ShipCity").Value
Rst.Close
dbConn.Close
Set Rst = Nothing
Set dbConn = Nothing