一个combobox绑定的数据源的类型是varchar,一个datagrid绑定表table1的一字段tableID类型也是varchar类型,我的datagrid绑定的select语句是:select * from table1 where table1.tableID=combobox.SelectText.
调试时系统指示我的sqlDataAdapter.Fill()错误;
我先修改select语句:select * from table1 结果运行正确.所以错误在where中.我不知道怎么就错了???高手低手给看看啊.

解决方案 »

  1.   

    select * from table1 where table1.tableID=combobox.SelectText 改为select * from table1 where table1.tableID='"+combobox.SelectText+"'
      

  2.   

    回复kv4000:
    我刚试了,运行没错,但是结果显示不对,当我在combobox选择一个值时,datagrid显示空,
      

  3.   

    看你combox中的id是否在table1中有此条对应的记录?
      

  4.   

    或者MessageBox.Show("你的sql语句")跟踪一下看看 sql语句内容是否正确?
      

  5.   

    id中有对应的记录(1000和1001),当我在combobox中选择1000时,结果中还是有1001的记录
      

  6.   

    :(怎么用MessageBox.Show跟踪?我把sql 语句写进去了 结果显示的是我的select语句:)
      

  7.   

    select * from table1 where table1.tableID='"+combobox.SelectText.trim()+"'试试~!
      

  8.   

    MessageBox.Show: select * from table where tableid='' 怎么成空值了?
      

  9.   

    select * from table1 where tableID like % || combobox.SelectText || %
      

  10.   

    ?????select * from table1 where table1.tableID='"+combobox.SelectText.trim()+这句你显示的是空??
      

  11.   

    combobox选择的值如果table1.tableID有,则datagrid应该显示的是符合table1.tableID='"+combobox.SelectText.trim()+"的值
    如果table1.tableID没有combobox选中的值,那么datagrid也显示空值.
    现在不关选择哪个,datagrid就是不变,显示的是table的全部值
      

  12.   

    private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    ComboBox comboBox = (ComboBox)sender;
    string reselect = "select * from table where tabel.tableid='"+comboBox1.SelectedText.Trim()+"'";
    //MessageBox.Show(reselect);
    sqlDataAdapter1=new SqlDataAdapter(reselect,sqlConnection1);
             sqlDataAdapter1.Fill(userDS1,"table");
    dataGrid1.SetDataBinding(userDS1,"table");
    }
    这里不会有错吧^^
      

  13.   

    string select = DropDownList1.SelectedItem.Text.Trim();
    string user_information = "select User_id,User_Name,Company,Telephone from User_inform where favour like '%"+select+"%'";
    SqlConnection myConnection = new SqlConnection(WebForm1.myconnect);
    SqlDataAdapter myCommand = new SqlDataAdapter (user_information,myConnection);
    myConnection.Open();
    DataSet ds = new DataSet();
    myCommand.Fill(ds,"User_inform");
    DataGrid1.DataSource=ds.Tables["User_inform"].DefaultView;
    DataGrid1.DataBind();
    myConnection.Close();
    这是我写的一段程序,你自己参考一下,你在页面上加个button,然后用button除法这个事件,老实说我也刚刚开始用asp.net,comboBox1_SelectedIndexChanged这个东西我吃不准
      

  14.   

    你的DropDownList数据绑定的不对吧?另外把你选择出来的值最好Trim() 一下