VB 中如何将数据库表中某个字段数据显示在TEXTBOX中?

2024-11-25 04:05:05
推荐回答(1个)
回答1:

Private Sub Command1_Click()

Dim adocn As New ADODB.Connection

Dim rs As New ADODB.Recordset
Dim strSql As String
strSql = "select * from 表名 where 字段名=" & 名字
adocn.Open
rs.Open strSql, adocn, 3, 3
If rs.EOF And rs.BOF Then
Set rs = Nothing
adocn.Close
MsgBox "查无信息", vbCritical + vbOKOnly, "信息"
Exit Sub
Else
Text1.Text = rs.Fields("想要显示字段名项目")
rs.Close
Set rs = Nothing
adocn.Close
End If

End Sub