我有一个“搜索”按钮来搜索datagrid中的数据/单元格,这是源的MySQL数据库。下面的代码块是成功搜索只有一列,但是当我添加其他列比搜索功能不工作,并且大多不会带来结果。以及区分大小写的错误,这对于只有一列是不成问题的。C#Winform的数据网格错误搜索值
我该如何安排代码才能够搜索所有行和列?
private void btnSearch_Click(object sender, EventArgs e)
{
DataView DV = new DataView(dbdataset);
DV.RowFilter = string.Format("Name LIKE '%{0}%'", txtSearch.Text);
dgvEkip.DataSource = DV;
// I added those columns below for search function as well but did not work well
/*
DV.RowFilter = string.Format("Telephone LIKE '%{0}%'", txtSearch.Text);
DV.RowFilter = string.Format("Email LIKE '%{0}%'", txtSearch.Text);
DV.RowFilter = string.Format("Surname LIKE '%{0}%'", txtSearch.Text);
DV.RowFilter = string.Format("City LIKE '%{0}%'", txtSearch.Text);
DV.RowFilter = string.Format("Adress LIKE '%{0}%'", txtSearch.Text);
*/
}
非常感谢,鹦鹉。
你尝试使用OR? https://msdn.microsoft.com/zh-cn/library/system.data.datacolumn.expression.aspx – KernelMode