[英]C# Winform search value on datagrid error
我有一个“搜索”按钮来搜索数据网格/数据网格中的源mysql db。 下面的代码块可以成功地仅搜索一列,但是当我添加其他列而不是搜索功能时效果不佳,并且大多数情况下不会带来结果。 同样,对于区分大小写的错误也仅适用于一列,这并不是一个问题。
如何安排代码以搜索所有行和列?
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);
*/
}
非常感谢Nuri。
使用AND来加入如下条件:
DV.RowFilter = string.Format("Telephone LIKE '%{0}%' AND Email LIKE '%{0}%'", txtSearch.Text, txtSearch2.Text);
您想在逻辑或中放置更多条件:例如
DV.RowFilter = string.Format("Name LIKE '%{0}%' OR Telephone LIKE '%{0}%' OR Email LIKE '%{0}%' ", txtSearch.Text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.