使用来自不同表的文本框进行搜索

  • 本文关键字:文本 搜索 c# mysql
  • 更新时间 :
  • 英文 :


我需要使textboxkeychange搜索来自两个不同表列的数据

public void searchData(string valuetoFind){

myconnection.Connection_db ();
string query = $"Select a.Date, a.Emp_ID, e.Firstname, e.Lastname, a.Time_In, a.Time_Out " +
$"from attendance a Inner Join emp_list e ON e.Emp_ID = a.Emp_ID" +
$"where concat(a.Emp_ID, e.Firstname) LIKE '%{valuetoFind}%'";
try
{
MySqlDataAdapter msda = new MySqlDataAdapter(query, Connection.conn);
DataTable dtbl = new DataTable();
msda.Fill(dtbl);
dgvattend.DataSource = dtbl;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

我需要一个搜索,我可以找到包含字母I类型的选定列上的任何数据…请帮助

你的问题当然可以改进,因为确实不清楚问题是什么。

但是看起来你的sql where子句是不正确的。where子句中的条件与AND/OR语句组合。所以你应该有

where a.Emp_ID LIKE '%valuetoFind%' AND e.Firstname LIKE '%valuetoFind%';

最新更新