返回首页

如何搜索DataGridView的内容在C#中使用TextBox和翻查键:我创建一个应用程序中,我采取了一个DataGridView中,文本框,搜索按钮............
  ;当我写在TextBox的文本,然后点击搜索按钮,是目前在DataGridView ......,如果perticular数据那么该行将会在第一的位置| tusharborade

回答

评论会员:2Montevina平台 时间:2012/02/04
你好图莎尔..
你可以试试这个..

在按钮的Click事件(私人无效中button1_Click(对象发件人,EventArgs的五)),你可以创建一个DataTable或DataSet,在其中您可以通过查询从数据库中找到的数据和反映在DataGridView的数据。

代码将是这样..


private void button1_Click(object sender, EventArgs e)//button click event

{

   DataTable dt= new DataTable;//creation of datatable which will be reflected in                         

                               //the datagrid view

   SqlDataAdapter adpt = new SqlDataAdapter("Select <field> from <table> where <field> like '" + textbox.Text + "%'",connectionobject); //query for database

   adpt.Fill(dt);//datatable to catch the fields from the database

   datagridview.DataSource = dt;

}</field></table></field>
评论会员:游客 时间:2012/02/04
sortami:你必须在第一时间绑定后,调用一个函数有此查询NBSPSqlDataAdapter的您的DataGridView;框"从表其中user_name="SELECT*"文本","此查询并绑定DataGridView的,如果你不明白电话给我这样做,完全地