'工程->引用->Microsoft ActiveX Data Objects 2.0 Library (后面为版本号)
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Combo1_Click()
rs.Open "SELECT * FROM TABLENAME WHERE NAME = '" & txtName.Text & "'", cn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Label1.Caption = rs!ID
Label2.Caption = rs!Memo
End If
End Sub
Private Sub Form_Load()
cn.ConnectionString = ""
cn.Open
'查询字符串可以上这里查
'http://www.connectionstrings.com/
End Sub
private sub form_load()
dim cn as new adodb.connection
dim rs as new adodb.recordset
dim strSql as string
with cn
.provider="sqloledb"
.connectionstring="data source=your server;initial catalog=your database;user id=your user;password=your password"
.open
end with
strSql = "select * from yourtable"
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open strsql, cn, adOpenDynamic, adLockOptimistic
End With
end sub