Private Sub Command5_Click()
Dim txtSQL As String
Dim rsSearch As ADODB.Recordset
If Trim(Text4.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Else
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
addFlag = True
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "
Text1.Text = rsSearch!UserID
Text2.Text = rsSearch!UserName
Text3.Text = rsSearch!Password
Combo1.Text = rsSearch!UserRole
End If
End If
End Sub
我想问下,这段查询程序错在哪里了,数据库连接在Form_Load中做过,为何它不报错误信息,但在我的Text中缺没有数据显示?????数据库是access做的
Dim txtSQL As String
Dim rsSearch As ADODB.Recordset
If Trim(Text4.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Else
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
addFlag = True
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "
Text1.Text = rsSearch!UserID
Text2.Text = rsSearch!UserName
Text3.Text = rsSearch!Password
Combo1.Text = rsSearch!UserRole
End If
End If
End Sub
我想问下,这段查询程序错在哪里了,数据库连接在Form_Load中做过,为何它不报错误信息,但在我的Text中缺没有数据显示?????数据库是access做的
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "没有执行查询啊~
rsSearch.Open txtSQL
Dim txtSQL As String
Dim rsSearch As ADODB.Recordset
If Trim(Text4.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Else
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
addFlag = True
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "
rsSearch.Open txtSQL'查询
Text1.Text = rsSearch!UserID
Text2.Text = rsSearch!UserName
Text3.Text = rsSearch!Password
Combo1.Text = rsSearch!UserRole
End If
End If
End Sub
Dim txtSQL As String
Dim rsSearch As ADODB.Recordset
If Trim(Text4.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Else
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
addFlag = True
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "
rsSearch.Open txtSQL'查询
'
'----
if rsSearch.recordcount=0 then msgbox "沒有些學號!":exit sub
Text1.Text = rsSearch!UserID
Text2.Text = rsSearch!UserName
Text3.Text = rsSearch!Password
Combo1.Text = rsSearch!UserRole
End If
End If
End Sub
Dim txtSQL As String
Dim rsSearch As ADODB.Recordset
If Trim(Text4.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Else
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
addFlag = True
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "
'======================
rsSearch.Open txtSQL,cn
'======================
Text1.Text = rsSearch!UserID
Text2.Text = rsSearch!UserName
Text3.Text = rsSearch!Password
Combo1.Text = rsSearch!UserRole
End If
End If
End Sub
现改成:txtSQL = "select * from UserMessage where UserID ='" & Text4.Text & " ' "
txtSQL = "select * from UserMessage where UserID = " & Val(Text4.Text) & ""如果UserID 是字符类型的,就:
txtSQL = "select * from UserMessage where UserID = '" & Text4.Text & " '"
其中txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "改为txtSQL = "select * from UserMessage where UserID ='" & Text4.Text & "'"rsSearch.Open txtSQL, Connection, adOpenDynamic, adLockBatchOptimistic
注:其中connection为链接字符串
adOpenDynamic 和 adLockBatchOptimistic为数据库打开模式
Dim rsSearch As ADODB.Recordset
改成
Dim rsSearch As new ADODB.Recordset
這樣就可以了!還有你可能要注意那個查詢詩句的寫法,字符型的一定要用引號引起來。
Dim txtSQL As String
Dim rsSearch As ADODB.Recordset
If Trim(Text4.Text) = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Else
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
addFlag = True
txtSQL = "select * from UserMessage where UserID = & Text4.Text & " ' "
rsSearch.Open txtSQL,,adOpenKeyset,adLockOptimistic '查询
Text1= rsSearch.Fields("UserID")
Text2= rsSearch.Fields("UserName")
Text3= rsSearch.Fields("Password")
Combo1= rsSearch.Fields("UserRole")
End If
End If
End Sub
来晚啦,也还是给你顶一下,你这段代码没有什么大问题,最后那个部分除了查询那一句其它的没什么问题,我改成那样只是我的习惯问题,你可以不用改!希望对你有所帮助!