数据网格错误

时间:2017-02-05 22:33:35

标签: c# mysql search datagridview

我有一个"搜索"按钮搜索数据网格中的数据/单元格,这是源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。

2 个答案:

答案 0 :(得分:0)

使用AND加入这样的条件:

DV.RowFilter = string.Format("Telephone LIKE '%{0}%' AND Email LIKE '%{0}%'", txtSearch.Text, txtSearch2.Text);

答案 1 :(得分:0)

您希望在逻辑OR中添加更多条件:例如

public class Team
    {
        public Team ParentTeam;
        public string Name;

        int Level
        {
            get
            {
                int i = 0;
                Team p = this.ParentTeam;
                while (p != null)
                {
                    i++;
                    p = p.ParentTeam;
                }
                return i;
            }
        }

        static IEnumerable<Team> Sort(IEnumerable<Team> list)
        {
            return list.OrderBy(o => o.Level);
        }
    }