如何从文本框中搜索输入的文本并在Winform中绑定数据网格中的记录? [英] how to search entered text from text box and bind records in datagrid in winform?
本文介绍了如何从文本框中搜索输入的文本并在Winform中绑定数据网格中的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的winform应用程序中,我正在datagrid中显示记录..并且有一个文本框.当我在文本框中输入该人的姓名时,该记录应显示在datagrid中. />
我为文本更改"尝试了此代码
在文字更改中:
hi in my winform application am displaying records in datagrid..and one textbox is there.when i enter name of the person in text box that record should display in datagrid.or display messg as record not found..?
i tried this code for Text Changed
in text change:
dv.RowFilter = "FirstName like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = dv;
public DataSet ds
{
get;
set;
}
public DataView dv
{
get;
set;
}
public Form1()
{
InitializeComponent();
ds = new DataSet();
dv = new DataView();
}
无法显示记录..当我在文本框中输入名字时,时间记录未显示在网格中..
任何人都可以建议我.为此可以提供更好的代码?
谢谢..
am not able to display records..when i enter first name in text box that time records not displaying in grid....
can any one suggest me.and better code for this??
thanks..
推荐答案
在
上尝试此代码
try this code on
private void textBox1_TextChanged(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Table1 where FirstName Like '" + textBox1.Text + "%' ", con);
SqlDataAdapter da= new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
da.SelectCommand.ExecuteNonQuery();
con.Close();
}
拉吉
这篇关于如何从文本框中搜索输入的文本并在Winform中绑定数据网格中的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文