先用循环将文本框内的条件连接成SQL条件语句的字符串,然后吗?

解决方案 »

  1.   

    先用循环将文本框内的条件连接成SQL条件语句的字符串
      

  2.   

    a=text1(0)
    b=text1(1)
    c=text1(2)(假设空)
    .
    .
    f=text1(5)
    select * from bb where name='&a &' and book=????????能否写条句子?
      

  3.   

    不行,注意文本为空时,字段名及"and"均不能出现,在循环中判断一下即可实现。
      

  4.   

    象 dbcontrols(泰山__抛砖引玉) 等人说的不错呀!试试吧!
      

  5.   

    看样子,你的条件不是同一字段,那就无法用循环啦,写n个判断语句吧(n=文本框数量)
    文本框均为空时会出错,你应当先判断一下。
    SqlStr="select * from bb where "
    A1=iif(trim(text1)="","","name='"&text1&"'")
    A2=iif(trim(text2)="","","book='"&text2&"'")
    .
    .
    .
    for i=1 to n
    if A&i<>"" then SqlStr=SqlStr & Ai & " and "
    next
    SqlStr=Left(SqlStr,Len(SqlStr)-5)     '去掉最后一个and
    试试!
      

  6.   

    看样子,你的条件不是同一字段,那就无法用循环啦,写n个判断语句吧(n=文本框数量)
    文本框均为空时会出错,你应当先判断一下。
    SqlStr="select * from bb where "
    A1=iif(trim(text1)="","","name='"&text1&"'")
    A2=iif(trim(text2)="","","book='"&text2&"'")
    .
    .
    .
    for i=1 to n
    if A&i<>"" then SqlStr=SqlStr & Ai & " and "
    next
    SqlStr=Left(SqlStr,Len(SqlStr)-5)     '去掉最后一个and
    试试!
      

  7.   

    sql="Select * from Table where 1=1"
    if trim(text1.text)="" then
    sql=sql & " and field1='" & trim(text1.text) & "'"
    end if
    .......
    if text6.text="" then
    sql=sql & " and field6='" & text6.text & "'"
    end if
      

  8.   

    使用控件数组与字段名数组,则只需要以下六行代码:
    sqlstr="select * from urtable where 1=1"
    for i=0 to 5
       if text(i).text<>"" then
        sqlstr=sqlstr & " and " & field(i) & " = " & text(i).text
       end if
    next i注意,where 1=1 是一个引导条件,以便后面全用And