给你一个例子 看一下就应该懂了 Private Sub cmdRead_Click() Dim RS As ADODB.Recordset Dim tSql As String Dim I As Integer Set RS = New ADODB.Recordset tSql = "Select * From TestUser Where XueHao=" & Trim(txtID.Text) RS.Open tSql, CN, adOpenStatic, adLockOptimistic If RS.RecordCount > 0 Then txtName.Text = RS.Fields("XingMing") txtScore.Text = RS.Fields("ChengJi") Else MsgBox "数据库中未找到相应记录", vbOKOnly, "提示" End If Set RS = Nothing End Sub
Private Sub Form_Load() Set CN = New ADODB.Connection 'QQ.mdb需要指定全路径,如C:\qq.mdb,具体位置自己修改。 CN.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\QQ.mdb;Uid=Admin;Pwd=" txtID.Text = "": txtName.Text = "": txtScore.Text = "" End Sub
Private Sub Form_Unload(Cancel As Integer) Set CN = Nothing End Sub