把Stry改为:
stry = "select * from information where 学号= '" & Text1.Text & "' or 姓名= '" & Text2.Text & "' or班级='" & Text3.Text & "' or 年龄='" & Text4.Text & "'or 性别='" & Text5.Text & "'"
stry = "select * from information where 学号= '" & Text1.Text & "' or 姓名= '" & Text2.Text & "' or班级='" & Text3.Text & "' or 年龄='" & Text4.Text & "'or 性别='" & Text5.Text & "'"
stry = "select * from information where 瀛﹀彿= '" & Text1.Text & "'銆€or 濮撳悕锛濄€€'" & Text2.Text & "'銆€or鐝骇锛?" & Text3.Text & "'銆€or銆€骞撮緞锛?" & Text4.Text & "'or銆€鎬у埆锛?" & Text5.Text & "'"
"'or年龄='" & Text4.Text & _
"'or性别='" & Text5.Text & "'"
是否应该改成这样,在or后要加空格
"'or 班级='" & Text3.Text & _
"'or 年龄='" & Text4.Text & _
"'or 性别='" & Text5.Text & "'"
对我成见满大的哦!
" where 学号= '" & Text1.Text &"'"就可以查询一旦改为stry = "select * from information" & _
" where 学号= '" & Text1.Text & _
Or "姓名='" & Text2.Text & "'"就提示查询表达式错误!
If strCon <> "" Then
If strW = "" Then
strW = strField & "='" & strCon & "'"
Else
strW = strW & " AND " & strField & " ='" & strCon & "'"
End If
End If
End Sub
==================
Dim strWhere As String
Dim strSql As String
strWhere = ""
GetWhere strWhere, Me.Text1.Text, "学号"
GetWhere strWhere, Me.Text2.Text, "姓名"
GetWhere strWhere, Me.Text3.Text, "班级"
GetWhere strWhere, Me.Text4.Text, "年龄"
GetWhere strWhere, Me.Text5.Text, "性别" strsql="select * from information"
if strwhere<>"" then
strsql=strsql & " where " & strwhere
end if=============================
试试看
" where 学号= '" & trim(Text1.Text) & _
"'or 姓名='" & trim(Text2.Text) & _
"'or 班级='" & trim(Text3.Text) & _
"'or 年龄='" & trim(Text4.Text) & _
"'or 性别='" & trim(Text5.Text) & "'" & _
" And True"
stry = "select * from information where 1=1 "
if trim(Text1.Text)<>"" then
stry=stry & "and (学号= '" & Text1.Text &"' "
end if
if trim(Text2.Text)<>"" then
stry=stry & "or 姓名='" & Text2.Text &"' "
end if
最后:if instr(stry,"and")>0 then
stry=stry & ")"
end if
数字型的要转为 Text2.Text(无需引号)
逻辑型也要转为true,false最好:
dim number,name,class as string
dim sex as boolean
dim old as interger
number=cstr(text1.text)
name=cstr(text2.text)
class=cstr(text3.text)
old =cint(text4.text)
if text5.text=1 then
sex=true
else
sex=false
endif
stry = "select * from information" & _
" where 学号= '" & number & _
"'or 姓名='" & name & _
"'or 班级='" & class & _
"'or 年龄=" & old & _
" or 性别=" & sex