vb 中如何让textbox控件里面显示数据库(SQL)的内容?

2024-11-18 18:24:06
推荐回答(4个)
回答1:

1.VB 代码如下:
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

回答2:

TextBox1.text = "(select a1列 from KH where 选出a1条件).tostring";
TextBox2.text = "(select a1列 from KH where 选出a1条件).tostring";
TextBox3.text = "(select a1列 from KH where 选出a1条件).tostring";
这样应该可以

回答3:

TextBox1.text = "select A1 from KH";
TextBox2.text = "select A2 from KH";
TextBox3.text = "select A3 from KH";
如果还要加条件在数据库语句后面加。

回答4:

如果是代码查询出来的,就手动赋值,如果绑定数据源,就自动显示