C#MySQL搜索查询
本文关键字:查询 搜索 C#MySQL | 更新日期: 2023-09-27 18:29:51
此代码具有搜索患者房间分配的功能:
else if(radioButton1.Checked == true)
{
DataTable table = new DataTable();
cmd = new MySqlCommand("Select * from patientinfo where LastName and FirstName = '" + textBox1.Text + "'", con.con);
reader = cmd.ExecuteReader();
MySqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
label2.Text = dr.GetString("LastName") + "," + dr.GetString("FirstName");
label6.Text = dr.GetString("Room");
if(label6.Text == "506")
{
label3.Text = "Payward Building";
}
else if(label6.Text == "507")
{
label3.Text = "Payward Building";
}
}
else
{
MessageBox.Show("No Data! Please Try Again", "Warning", MessageBoxButtons.OK);
con.Close();
}
我在搜索患者姓名时遇到困难,该姓名存储在数据库中的两个不同字段FirstName
和LastName
中。我只想输入名字和姓氏的组合。
尝试将SQL代码更改为:
cmd = new MySqlCommand("Select * from patientinfo where LastName + ' ' + FirstName like '%" + textBox1.Text + "%'", con.con);