中华建造网真的假的:VB组合查询

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 15:22:42
Private Sub Command4_Click()

If Text1.Text = "" And Text2.Text = "" And Combo1.Text = "" Then
Adodc1.RecordSource = "select * from 维护表 where 申请日期 like + '" & DTPicker1 & "'+ '%'"
Adodc1.Refresh
Else
If Text1.Text <> "" And Text2.Text <> "" And Combo1.Text = "" Then
Adodc1.RecordSource = "select * from 维护表 where 楼房编号 like + '" & Text1 & "'+ '%'"
Adodc1.RecordSource = "select * from 维护表 where 寝室号 like + '" & Text2 & "'+ '%'"
Adodc1.Refresh

Else
If Combo1.Text <> "" And Text1.Text = "" And Text2.Text = "" Then
Adodc1.RecordSource = "select * from 维护表 where 是否已修 like + '" & Combo1 & "'+ '%'"
Adodc1.Refresh
Else
If Text1.Text <> "" And Combo1.Text <> "" Then
Adodc1.RecordSource = "select * from 维护表 where 楼房编号 like + '" & Text1 & "'+ '%'"
Adodc1.RecordSource = "select * from 维护表 where 是否已修 like + '" & Combo1 & "'+ '%'"
Adodc1.Refresh
Else
If Combo1.Text <> "" And DTPicker1.Value <> "" Then
Adodc1.RecordSource = "select * from 维护表 where 是否已修 like + '" & Combo1 & "'+ '%'"
Adodc1.RecordSource = "select * from 维护表 where 申请日期 like + '" & DTPicker1 & "'+ '%'"
Adodc1.Refresh
End If
End If
End If
End If
End If
End Sub
此段查询我想完成几个字段的组合查询.但只能执行到第3个查询.下面就不行了.下面的根据text1和combo1的组合查询及根据combo1和dtpicker1的组合查询却不行
另Adodc1.RecordSource = "select * from 维护表 where 楼房编号 = '" & Text1.text & "'"完全查询怎么不行.非要Adodc1.RecordSource = "select * from 维护表 where 楼房编号 like + '" & Text1 & "'+ '%'"模糊查询才能行.是不是完全查询语句错了

1.最重要的问题结构不对
应该是
if...then
elseif....then
elseif...then
....
else
end if
而不该是现在的结构
2.那个不行可能存在问题是楼房编号要是数值型的字段,那么
where 楼房编号 = '" & Text1.text & "'"
应该改成
where 楼房编号 = " & Text1.text & ""
3.
Adodc1.RecordSource = "select * from 维护表 where 申请日期 like + '" & DTPicker1 & "'+ '%'"
这个不好这么写吧
Adodc1.RecordSource = "select * from 维护表 where 申请日期 = '" & DTPicker1 & "'"
这样子好点