我用TableAdpter增加一个查询。希望实现模糊查询。如select * from table1 where name like ‘%张%’and dress like '%北京%'
其中,希望把地址和姓名设成参数。我是这样写的:select * from table1 where name like ? and dress like ?
然后,在界面上放两个combobox1和combobox2。调用的代码如下:string a="%"+combobox1.text+"%";
string b="%"+combobox2.text+"%";
TableAdapter.Myselect(table1,a,b);可是我绑定的dataGridView却查不出任何数据。无论我在combobox中输入什么。感觉应该是很简单的问题吧,可是为什么不行呢?
希望大家不吝赐教!!!

解决方案 »

  1.   

    使用字符串
    string strSql = "select * from table1 where name like '%"+combobox1.text+"%' and dress like '%"+combobox2.text+"%'"
      

  2.   

    改成这样看看
    string select =  "select * from table1 where name like '%"+combobox1.text+"%' and dress like '%"+combobox2.text+"%'";
    TableAdapter.Myselect(select);
      

  3.   

    可能大家没有明白我的意思。如果手工创建SqlCommand和SqlConnection,确实可以用上面的查询字符串赋给SqlCommand的CommandText.
       但是,我是想用TableAdapter的“添加查询”的方法。在添加查询的向导中,用系统提供的“查询分析器”中,是不能输入类似Combobox1等的。只能用纯sql语句加上参数。   反正叙述比较麻烦。不行就算了。我多试几次吧。
      

  4.   

    就是
    不过要多学学SQL语句怎么来写
      

  5.   

    SQL是很有用的
    一定要学啊
      

  6.   

    string strSql = "select * from table1 where name like '%"+combobox1.text+"%' and dress like '%"+combobox2.text+"%'"
    八步的就可以了,不需要string a= ◎!#!◎#!
      

  7.   

    string strSql = "select * from table1 where name like '%"+combobox1.text+"%' and dress like '%"+combobox2.text+"%'"