注册 登录
编程论坛 VB6论坛

如何通过数据如何通过数据库某个表中的某列的信息来查询出这一行的所有信息并且显示出来库某个表中的某列的信息来查询出这一行的所有信息并且显示出来

childH 发布于 2020-03-06 22:54, 1649 次点击
如何通过数据库某个表中的某列的信息来查询出这一行的所有信息并且显示出来
SQL Server中 数据库名:bill 表为:dbo.student  如下图:
VB界面如下图:
如何通过输入ID来查询对应的ID所在行的信息。 我不知道哪里写的不对,一晚上没找出原因,求大神帮忙看看。
Private Sub Command1_Click()
Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=bill;"
  Adodc1.RecordSource = "select id,name,sex,age from dbo.student where id=" & Val(Text1)
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1
End Sub
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
1 回复
#2
kinger12192020-03-12 10:42
Private Sub Command1_Click()
Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=bill;"
If IsNumeric(Text1.Text) = False Then
 ' 判断文本框内容是否为数字  最好加上文本输入判断,否则输入查询的不是数字,点击还是会出现你上面的错误
MsgBox "数量只能输入数字", 17, "错误提示"
Exit Sub
End If
 Adodc1.RecordSource = "select id,name,sex,age from student where id='" + Text1.Text + "'"  
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1
End Sub  
1