我现在做了一个查询然后绑定到了dataGridView中,以下代码是窗体Load事件中的代码:
{
              SqlConnection sql = new SqlConnection(sqlstr);
            SqlCommand sqlc = new SqlCommand();
            sqlc.Connection = sql;
            sqlc.CommandText = "select ygxm 员工姓名,dlmc 登录名称,yhkl 用户口令,bzmc 班组名称,glzz 岗位名称 from b_yhbm where dwbm=(select zzdm from b_zz where zzmc='" + comboBox2.SelectedItem.ToString() + "') and bzdm=2 order by bzdm";
            ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(sqlc);
            sql.Open();
            sda.Fill(ds, "t1");
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "t1";}
我在一个button1的单击事件中,想实现上表中的‘登录名称’这列的模糊查询:代码如下:
{
              DataRow dr= ds.Tables["t1"].Select("登录名称 like 'w%'")[0];
          
            dataGridView1.DataMember ="t1";
            dataGridView1.DataSource = ds;
}
但是,单击button1按钮后,dataGridView没有显示出模糊查询的记录,一点反应都没有!请帮忙解决!谢谢!

解决方案 »

  1.   

    帮忙写个可以实现的语句!可能是上面没有更新dataTable的缘故造成的,应该怎么做,请帮忙写段语句!
      

  2.   

    绑定数据源
     写成. ds.Tables[0];或ds.Tables[0].defaultview;
      

  3.   

    过滤使用DataTable.DefaultView.RowFilter:          ds.Tables["t1"].DefaultView.RowFilter="登录名称 like 'w%'"; 
      

  4.   

    DataRow dr= ds.Tables["t1"].Select("登录名称 like 'w%'")[0]; 
    这行好像写的不对,应该再建个 new dataset  dt2=ds.Tables["t1"].Select("登录名称 like 'w%'")[0]; 
    绑定这个dataset
      

  5.   

    4楼的方法正确!但是select怎么使用呢?
      

  6.   

    ...晕..
     Select 相当于SQL 里的WHERE 你说呢...