从alphanumaric值查找查询

lqfhib0f  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(263)

实习生id是一个字母数字值。
问题是运行程序后,搜索代码只对数字有效。不是字母数字的。我该如何解决这个问题。

private void button1_Click(object sender, EventArgs e)
    {

        if (txtsearch.Text != "")
        {
            MessageBox.Show("Please type intern number");
        }
        else
        {
            try
            {
                con.Open();
                string SelectQuery2 = "SELECT * FROM interndetails WHERE internnumber =" + Convert.ToString(txtsearch.Text);
                cmd4 = new MySqlCommand(SelectQuery2, con);
                mdr2 = cmd4.ExecuteReader();
                if (mdr2.Read())
                {
                    textBox11.Text = mdr2.GetString("name");
                    textBox9.Text = mdr2.GetString("idnumber");
                    textBox6.Text = mdr2.GetString("status");
                    textBox12.Text = mdr2.GetString("statusdate");
                    textBox13.Text = mdr2.GetString("intakedate");
                    textBox14.Text = mdr2.GetString("fplacementdate");
                    textBox10.Text = mdr2.GetString("secbrdpt");
                    textBox15.Text = mdr2.GetString("periodcomplertion");
                    mdr2.Close();
                    con.Close();
                }
                else
                {
                    MessageBox.Show("No Interns were found!");
                    txtsearch.Clear();
                    txtsearch.Focus();
                }
                con.Close();
            }
            catch (MySqlException x)
            {
                MessageBox.Show(x.Message);
                con.Close();
            }

        }

    }

}
fsi0uk1n

fsi0uk1n1#

可能对你有帮助吗
选择*from interndetails where concat(internnumber,'')='“+convert.tostring(txtsearch.text)+'”

laximzn5

laximzn52#

这样的方法应该有用:

string SelectQuery2 = "SELECT * FROM interndetails WHERE internnumber = @internNumber";
cmd4 = new MySqlCommand(SelectQuery2, con);
cmd4.Parameters.Add("@internNumber", MySqlDbType.String).Value = txtsearch.Text;

相关问题