模糊查询就好了,where name like .........

解决方案 »

  1.   

    DataView dv=DataGirdView.DataSource as DataView;
    dv.Filter="Name like '" + textbox.Text + "%'";DataGirdView.DataSource=dv;
    DataGridView.DataBind();
      

  2.   

    数据量不大的话,写一个TEXTCHANGED事件,在事件里面使用DATAGRIDVIEW的filter。
    如果数据很多,这样用户体验是不是会比较差,用个BUTTON事件再筛选会不会更好?
      

  3.   

    首先要判断下  textbox.Text的值是否为空,否则会报异常的!! 
      

  4.   

    先将绑定到dgv的数据源存在dt中,然后根据TEXTBOX的值在textchanged事件中过滤dt,将过滤后的帮赋给dgv,OK
      

  5.   

    private void textBox2_TextChanged(object sender, EventArgs e)
            {
                string str = textBox2.Text;
                SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=pubs;User ID=sa;Password=sa");
                conn.Open();
                string strCmd = "select * from titles where title like '%" + str + "%'";
                SqlDataAdapter da = new SqlDataAdapter(strCmd, conn);
                DataSet ds = new DataSet();
                da.Fill(ds, "titles");
                dataGridView1.DataSource = ds.Tables[0];
            }