vb查询SQL语句的问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 18:01:31
小弟想通过vb查询SQL中的数据,已经成功连接SQL,设定了4个查询条件框,但按钮只设了一个,我用的语句是这样的
“Private Sub Command1_Click()
msql = "select*from 专业维护 where 专业='" & Text1 & "'and 班别='" & Text2 & "'and 学号='" & Text3 & "''and 年级='" & Text4 & "'"
但如果这样的话,在查询过程中,必须把4个条件都填上才能查到数据,只输入其中的1个或2个都无法显示,我想只要随意输入条件就能查询到相应的数据,不知如何修改才能实现,望高手指点,万分感谢!!!

text1=text1.text
text2=text2.text
text3=text3.text
text4=text4.text
先把值赋给这四个变量:(如上)

分条件呀:
if text1<>"" and text2<>"" and text3<>"" and text4<>"" then
msql = "select*from 专业维护 where 专业='" & Text1 & "'and 班别='" & Text2 & "'and 学号='" & Text3 & "'and 年级='" & Text4 & "'"
end if
(上面这句是输入四个条件的查询语句)

if text1="" and text2<>"" and text3<>"" and text4<>"" then
msql = "select * from 专业维护 where 班别='" & Text2 & "'and 学号='" & Text3 & "'and 年级='" & Text4 & "'"
end if

if text1<>"" and text2="" and text3<>"" and text4<>"" then
msql = "select*from 专业维护 where 专业='" & Text1 & &