gpt4 book ai didi

C# MySQL 搜索查询

转载 作者:行者123 更新时间:2023-11-30 22:27:54 24 4
gpt4 key购买 nike

此代码具有搜索患者房间分配的功能:

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();
}

我在搜索患者姓名时遇到困难,它在数据库中存储为两个不同的字段,FirstNameLastName。我只想输入名字和姓氏的组合。

最佳答案

尝试将您的 SQL 代码更改为:

cmd = new MySqlCommand("Select * from patientinfo where LastName + ' ' + FirstName like '%" + textBox1.Text + "%'", con.con);

关于C# MySQL 搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34721729/

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