非计算机专业的一个VB 问题

来源:百度知道 编辑:UC知道 时间:2024/09/13 05:11:58
Private Sub cmdChaX_Click()
If TxtXM.Text <> "" Then
Adodc1.RecordSource = "select * from 12 where 姓名=" & TxtXM.Text
Adodc1.Refresh
TxtNL.DataField = "年龄"
End If
End Sub
————————————
为什么提示出错,怎么比较简单的改进。

错在这段:
"select * from 12 where 姓名=" & TxtXM.Text

应改为

"select * from 12 where 姓名='" & TxtXM.Text & "'"

按你的数据库设计,姓名应该是字符串的,TxtXM.txt 要用单引号引出来才对的,