gpt4 book ai didi

c# 使用文本框搜索连接列

转载 作者:行者123 更新时间:2023-11-30 21:48:31 25 4
gpt4 key购买 nike

如何搜索串联的列?我知道如何进行单列搜索,但我想要的是搜索连接的列。请帮助我

public void searchenrolee()
{
MySqlCommand cmd = connection.CreateCommand();
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);

try
{
connection.Open();

string value = "Fullname";

cmd.CommandText = String.Format(
@"Select EEid, CONCAT(Fname,' ', Mname,' ', Lname) AS Fullname, DateRegistered
from studenttbl
where {0} like @searchKey AND year(DateRegistered) = '" + cbStudYear.selectedValue.ToString() + "' AND Enrollingto = '" + cbSLGrade.selectedValue.ToString() + "' order by EEid desc", value);

cmd.Parameters.AddWithValue("@searchKey", '%' + tbsearchEnrolee.Text.ToString() + '%');
MySqlDataAdapter kuhain = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dgvStudentList.DataSource = ds.Tables[0].DefaultView;

connection.Close();
}
catch
{
connection.Close();
}
}

private void tbsearchEnrolee_TextChanged(object sender, EventArgs e)
{
searchenrolee();
}

最佳答案

Crowcoder 的回答

public void searchenrolee()
{
MySqlCommand cmd = connection.CreateCommand();
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);

try
{
connection.Open();

string value = "Fullname";

cmd.CommandText = String.Format(
@"Select EEid, CONCAT(Fname,' ', Mname,' ', Lname) AS Fullname, DateRegistered
from studenttbl
where CONCAT(Fname,' ', Mname,' ', Lname) like @searchKey AND year(DateRegistered) = '" + cbStudYear.selectedValue.ToString() + "' AND Enrollingto = '" + cbSLGrade.selectedValue.ToString() + "' order by EEid desc", value);

cmd.Parameters.AddWithValue("@searchKey", '%' + tbsearchEnrolee.Text.ToString() + '%');
MySqlDataAdapter kuhain = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dgvStudentList.DataSource = ds.Tables[0].DefaultView;

connection.Close();
}
catch
{
connection.Close();
}
}

private void tbsearchEnrolee_TextChanged(object sender, EventArgs e)
{
searchenrolee();
}

关于c# 使用文本框搜索连接列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48366980/

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