VB中联合查询算法

我发明了一个查询用的口袋算法:

    当我们的查询组合条件很多的时候,我们就把各个查询条件写入一个变量(这个变量就是口袋),这个变量跟在查询语句的where后边,这样当口袋里的条件同时通过的时候,就是我们有查的结果了
程序是这样的——
'---------------------------------------------查询项目函数-----------------------------------------------
Public Sub data_select()

      '查询的时候,判断各个栏目内有没有内容,如果有加入查询条件变量中
        
      '------------------------------------企业名称判定-------------------------------------like '%" + T7.Text + "%'(包含提交信息的任何文本)
      If cxcc = "" Then
        If gly.Text1.Text <> "" Then cxcc = "企业名称 like'%" + gly.Text1.Text + "%'"
      Else
        If gly.Text1.Text <> "" Then cxcc = cxcc + " and 企业名称 like'%" + gly.Text1.Text + "%'"
      End If
        
      '--------------------------------------法人判定---------------------------------------
      If cxcc = "" Then
        If gly.Text2.Text <> "" Then cxcc = "法人 like'%" + gly.Text2.Text + "%'"
      Else
        If gly.Text2.Text <> "" Then cxcc = cxcc + " and 法人 like'%" + gly.Text2.Text + "%'"
      End If
      
      '------------------------------------资质等级判定-------------------------------------
      If cxcc = "" Then
        If gly.Text3.Text <> "" Then cxcc = "资质等级 like'%" + gly.Text3.Text + "%'"
      Else
        If gly.Text3.Text <> "" Then cxcc = cxcc + " and 资质等级 like'%" + gly.Text3.Text + "%'"
      End If
        
      '------------------------------------证书编号判定-------------------------------------
      If cxcc = "" Then
        If gly.Text4.Text <> "" Then cxcc = "证书编号 like'%" + gly.Text4.Text + "%'"
      Else
        If gly.Text4.Text <> "" Then cxcc = cxcc + " and 证书编号 like'%" + gly.Text4.Text + "%'"
      End If

        '定义查询语句(其中cxcc是查询条件字符串变量)
        cxtj = "select * from project where " + cxcc + "order by 项目序号"
        
        
        '调用遍历会员的资料函数(显示查询结果用)
        op
        
        '清空查询条件变量
        cxcc = ""
End Sub


文章来自: 本站原创
引用通告地址: http://www.cn-sohu.com/bolg/trackback.asp?tbID=367
Tags:
评论: 0 | 引用: 0 | 查看次数: 226
发表评论
你没有权限发表留言!
分享到: