如何搜索连续列?我知道如何进行单列搜索,但我想要的是搜索连接列..请帮助我
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();
}
答案 0 :(得分:0)
通过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();
}