简体   繁体   English

C#Winform在DataGrid错误上搜索值

[英]C# Winform search value on datagrid error

I have a "Search" button to search data/cell in datagrid which is source mysql db. 我有一个“搜索”按钮来搜索数据网格/数据网格中的源mysql db。 The code block below is success to search for only a column but when i add for other columns than searching functioning doesn't work well and mostly not bring results. 下面的代码块可以成功地仅搜索一列,但是当我添加其他列而不是搜索功能时效果不佳,并且大多数情况下不会带来结果。 As well given error for case-sensitive which is not a problem for only one column. 同样,对于区分大小写的错误也仅适用于一列,这并不是一个问题。

How can i arrange the code to be able to search all rows and columns? 如何安排代码以搜索所有行和列?

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);
            */
        } 

Thanks a lot, Nuri. 非常感谢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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM