string sql = "select  b.id,b.brandid,m.name,b.priceradio,b.fees,b.costmin,b.costmax,b.re,b.begindate,b.enddate,b.opepid " +
                            ",case b.applyto when 1 then '化学品' when 2 then '耗材' else '未知' end as applyto " +........
if (this.RadioButtonList1.SelectedValue.Equals("1"))
        {
            sql += "";
        }
        else
        {
            
        }
SQL是gridview绑定数据的,要如何写代码能让运行时‘化学品’,‘耗材’通过RadioButtonList1,的选定,分别显示,求助。

解决方案 »

  1.   


    string sql = "select b.id,b.brandid,m.name,b.priceradio,b.fees,b.costmin,b.costmax,b.re,b.begindate,b.enddate,b.opepid " +
      ",case b.applyto when 1 then '化学品' when 2 then '耗材' else '未知' end as applyto from tb where b.applyto =" + this.RadioButtonList1.SelectedValue;
      

  2.   

    string sql=""select b.id,b.brandid,m.name,b.priceradio,b.fees,b.costmin,b.costmax,b.re,b.begindate,b.enddate,b.opepid where 1=1
    if(rdbtn化学品.Checked==true)
    {
         sql+="";
    }
      

  3.   

    if (this.RadioButtonList1.SelectedValue.Equals("1"))
      {
      string sql = "select b.id,b.brandid,m.name,b.priceradio,b.fees,b.costmin,b.costmax,b.re,b.begindate,b.enddate,b.opepid ...from talbe_name1 as b,table_name2 as a where a.brandid=b.brandid and brandname='化学品'....
     dataset ds=......
     gridview1.datasource=ds;
    gridview1.databind();
        }
      else
      {
        string sql = "select b.id,b.brandid,m.name,b.priceradio,b.fees,b.costmin,b.costmax,b.re,b.begindate,b.enddate,b.opepid ...from talbe_name1 as b,table_name2 as a where a.brandid=b.brandid and brandname='化学品'.... 
        dataset ds=......
       gridview1.datasource=ds;
       gridview1.databind();  }
    直接通过下拉框的选择来决定sql语句的写法,然后执行查询,根据不同条件的查询把返回结果绑定到gridview控件
      

  4.   

    感谢大家的帮忙,前两种我试了,但是没成功,
    wangzhi0321
    的方法管用,不过写起来麻烦啊