组合查询:同时满足两个以上条件的查询
条件之间的关系:“”与“、”或(即”AND”、”OR”)
以机房查看上机状态为例
实现组合查询前提
1、使查询语句识别combox中选择的信息
以下代码使组合关系中的信息使查询语句可识别
如:cb8.Text中的“与”用“and”表示,“或”用“or”表示,strcon4为赋值变量的名称
Select Case cb8.Text ‘开始
Case "与"
strcon4 = "and"
Case "或"
strcon4 = "or"
End Select ‘结束
字段名中,将控件中可选择的内容转换为查询语句可识别的信息
Select Case cb3.Text
Case "卡号"
strcon5 = "cardno"
Case "姓名"
strcon5 = "studentName"
Case "上机日期"
strcon5 = "ondate"
Case "下机日期"
strcon5 = "offdate"
Case "上机时间"
strcon5 = "ontime"
Case "下机时间"
strcon5 = "offtime"
Case "消费金额"
strcon5 = "consume"
Case "余额"
strcon5 = "cash"
End Select
操作符中的符号即为可识别,所以不需要转换
判断一个条件的查询
Txtsql=查询表+查询条件
txtsql = "select * from line_Info where " & strCon1 & cb4.Text & "'" & Trim(txtquery1.Text) & "'"
strCon1:为字段名
cb4.Text:为操作符(<、>、=、<>)
txtquery1.Text:查询内容
判断两个条件的语句
在满足条件一的情况下
Txtsql=条件一+(条件之间关系)+条件二
txtsql = txtsql & " " & strcon3 & " " & strCon2 & " " & cb5.Text & "'" & Trim(txtquery2.Text) & "'"
strcon3:为两个条件之间的关系(与、或等)
strCon2:字段名
cb5.Text:为操作符(<、>、=、<>)
txtquery2.Text:查询内容
判断三个条件语句
在满足条件一和条件二的情况下
TxtSQL=”条件一()条件二”&(strcon4)& 条件三
TxtSQL = TxtSQL & strcon4 & " " & strcon5 & cb6.Text & "'" & Trim(txtquery3.Text) & "'"
Strcon4:为两个条件之间的关系(与、或等)
strCon5:字段名
cb6.Text:为操作符(<、>、=、<>)
txtquery3.Text:查询内容