窗体有Adodc+DataGrid显示数据集还有不少 text控件、combo控件、check控件 用来输入查询条件 现在有问题啊如果,这些条件里面不想输入,这个查询怎么写啊? 先判断是否有输入,再组合成查询语句?

解决方案 »

  1.   

    难道都要用 if text1.text <>'' 
                            zhen sql语句 = “and 手机号码 = ' & 手机号码那个格子里的内容 & '”
               end if???这样 都要用if 来筛选 程序不是很冗长嘛
      

  2.   

    dim strsql as string
    dim strwhere1 as string
    dim strwhere2 as string
    dim strwhere3 as stringif text1.text="" then
        strwhere1=""
    else
        strwhere1=" and a='"& text1.text &"'"
    end if
    if text2.text="" then
        strwhere2=""
    else
        strwhere2=" and b='"& text2.text &"'"
    end if
    if text3.text="" then
        strwhere3=""
    else 
        strwhere3=" and c='"& text3.text &"'"
    end ifstrsql=" select * from tablename where 1=1 " & strwhere1 & strwhere2 & strwhere3
      

  3.   


    有29个 text   7个 combo   还有6个check   
      

  4.   

    用控件数组+FOR循环
    设置相同的默认值,以便判断
      

  5.   

    dim a(28) as String
    '想办法把字段的名字存到这个数组
     
    S="Select * From TABL1 Where "
    For i = 0 To 28
      if Text1(i).Text<>"" Then
        S=S & " And " & a(i) & " = '" & Text1(i).Text & "'" 
      Endif
    next i
      

  6.   

    用SQL啊,,查询条件为strx(N)=".....",没选中的STRX(N)="".
    在SQL里用 strx(N) & strx(N)