("select * from 借书表 where ID = '" & idt.Text & "' or 图书编号='" & bookid.Text & "' or 条形码='" & tiaomat.Text & "'")
比如我想查询 id 为 33的人 idt.text 写上33 可以查到
但这时 bookid.text或tiaomat.text 里是""它连这些空的一起查了 怎么办? 非要在VB中判断 然后做三次查询吗?
比如我想查询 id 为 33的人 idt.text 写上33 可以查到
但这时 bookid.text或tiaomat.text 里是""它连这些空的一起查了 怎么办? 非要在VB中判断 然后做三次查询吗?
你这样做:
用一个combobox列出ID, 图书编号, 条形码
这样又用户来选择条件
再来一个textbox来装对应字段的值
再来一个command 按钮 .caption="添加条件"
再来一个command按钮.caption="执行"
你还可以设计得复杂一点加上"或者"查询你也可以让用户自己写sql最后3个结合在一起才是最方便的如果功能要够强大就让它以数据库里的所有表的所有字段为条件,任意组合查询
sql = ""If Check1(0).Value = 1 Then
If sql = "" Then
sql = "where 客户='" & DataCombo2.BoundText & "'"
Else
sql = sql & "and 客户='" & DataCombo2.BoundText & "'"
End If
End IfIf Check1(1).Value = 1 Then
If sql = "" Then
sql = "where 跟单员='" & DataCombo1.BoundText & "'"
Else
sql = sql & "and 跟单员='" & DataCombo1.BoundText & "'"
End If
End If