gpt4 book ai didi

C# Winform 在数据网格上搜索值错误

转载 作者:行者123 更新时间:2023-11-29 19:27:12 26 4
gpt4 key购买 nike

我有一个“搜索”按钮来搜索数据网格中的数据/单元格,它是源 mysql 数据库。下面的代码块成功地仅搜索一列,但是当我添加其他列时,搜索功能无法正常工作,并且大多不会带来结果。还给出了区分大小写的错误,这对于一列来说不是问题。

如何安排代码以便能够搜索所有行和列?

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

非常感谢,努里。

最佳答案

您想在逻辑“或”中放入更多条件:例如

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

关于C# Winform 在数据网格上搜索值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42058101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com