public partial class Form2 : Form
{
OleDbConnection conn1 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\dgovan\documents\visual studio 2015\Projects\LenovoWarranty2\LenovoWarranty2\LenovoWarranty.accdb");
DataTable dt = new DataTable();
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
fillData();
}
private void fillData()
{
//Init
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand cmd;
//statement
string sql = "SELECT * FROM Warranty";
cmd = new OleDbCommand(sql, conn1);
adapter.SelectCommand = cmd;
//fill
adapter.Fill(dt);
//bind
dataGridView1.DataSource = dt;
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("SerialNumber LIKE '%{0}%'", txtSearch.Text);
dv.RowFilter = string.Format("CompanyName LIKE '%{0}%'", txtSearch.Text);
//BIND
dataGridView1.DataSource = dt;
}
}
每当我在txtSearch文本框中输入任何内容时 - 没有任何反应?有谁能发现这个问题?
我试图允许用户使用txtbox_textchanged事件从我的数据库中过滤SerialNumber + CompanyName字段,因此每当输入一个字符时,行都会过滤。
答案 0 :(得分:1)
尝试
dataGridView1.DataSource = dv.ToTable();
此外,我相信您将覆盖过滤条件,而不是将它们组合在一起。我认为只会使用CompanyName
过滤器