例如有1GRIDVIEW控件 
数据源默认为 select * ftom stu我想在代码中点击搜索实现如
select * ftom stu where name = {0}
还有
select * ftom stu where name like {0}
或者
select * ftom stu where name like {0} and city ={1}
的情况。怎么设置呀。

解决方案 »

  1.   

    那你 把where 子句传递进去
      

  2.   

    问题是同一个参数可能这个是= 哪个是LIKE
    这个怎么办怎么动态 设置呀
      

  3.   

    string sql ="select * ftom stu"
           根据自己需求
    if(...........)
    {
           sql+="where name = {0}";
    }
    if(...........)
    {
           sql+="where   name like {0}";
    }
      

  4.   

    这个是动态生成sQL语句的问题,你必须写点代码实现,而不能直接利用配置数据源实现。
    具体方法如下:
    1、由于你的Select * from stu都是一样的,所以可以把条件语句定义为一个字符串(conditionStr)
    2、根据不同的搜索条件,更新你的conditionStr,具体方法和antiking(Q狼E行) 说的差不多
    3、最好把两个字符串合并。
    4、用DataSet或者DataReader(大数据量查询)来绑定你的GridView。