WEB from中有几个WEB 控件,
当我点出"查询按钮"是,遍历那些控件,忽略为空或特定值的文本框和下拉菜单.然后连接生成一个SQL语句.
只针对单表.请问,应如何遍历呢?如何连接成一个SQL呀.谢谢

解决方案 »

  1.   

    foreach (Control con in Page.Controls)
      

  2.   

    foreach (Control control in Page.Controls)
    {
      ...
    }
      

  3.   

    象下面这样实现:
    SQL="Select Distinct PlasticBOM.GoodsID, "
    SQL=SQL & "PlasticBOM.CustomerID, "
    SQL=SQL & "PlasticBOM.Status, "
    SQL=SQL & "PlasticBOM.FileNo, "
    SQL=SQL & "PlasticBOM.NewRev, "
    SQL=SQL & "PlasticBOM.CreateDate, "
    SQL=SQL & "PlasticBOM.ModifyDate, "
    SQL=SQL & "Goods.GoodsName, "
    SQL=SQL & "PlasticBOM.AuditStatus, "
    SQL=SQL & "PlasticBOM.ApproveStatus "
    SQL=SQL & "From "
    SQL=SQL & "PlasticBOM,Goods "
    SQL=SQL & "Where "
    SQL=SQL & "PlasticBOM.GoodsID=Goods.GoodsID "
             if BOMCustomer<>"" and BOMCustomer<>"输入客户编码查询" then
    if selecttype3=0 then
    SQL=SQL & "and "
    SQL=SQL & "PlasticBOM.CustomerID>'" & BOMCustomer & "' "
                      end if
            end if
    连接时判断需连接文本框或其它控件值的情况
      

  4.   

    这是在asp中写的!
    看得出来它的思想的
      

  5.   

    先把控件里的值取出来。然后使用SQL语句累加
    string strsql="select * from table where 1=1";
    if(参数1!="")
    {
    strsql=strsql+" and 条件"    //注意and前面加一个空格
    }
    if(参数2!="")
    {
    strsql=strsql+" and 条件" 
    }
    参数多也一样。
      

  6.   

    比如我有三个文本框(txt_name,txt_deputy,txt_age),一个下拉列表(dp_sex).条件:文本框为空时,表全部,下拉列表,selected.item.value为ALL时全选
    在SQL 语句中忽略相应的条件,否则根据条件来实现
    sql="SELECT * FROM table "
    sql=sql&"where"
    sql=sql&"相应条件"
    下面该咋写呢
      

  7.   

    string sql ="select * from a where 1=1 "
    foreach (Control control in Page.Controls)
    {
        sql += control.name +" = " control.value;
    //致于control.name(有可能是id 总之是和你的字段名对应) 和 control.value 就得你自已想办法.法取了,是  }
      
      

  8.   

    哪位老大写一个完整的嘛,从FOREACH开始.谢了我太菜了