C#Mysql行无法验证
我想验证MySQL数据库中的二维码。但是二维码是无效的,我想进入我的程序 如何验证它C#Mysql行无法验证,c#,mysql,qr-code,C#,Mysql,Qr Code,我想验证MySQL数据库中的二维码。但是二维码是无效的,我想进入我的程序 如何验证它 if (decodeStr == null) { MessageBox.Show("There is no QR Code!"); } else { player.Play(); ConnectToDatabase(); MySqlCommand cmd = new MySqlCommand("Select Name, LPN From visitors Where pa
if (decodeStr == null)
{
MessageBox.Show("There is no QR Code!");
}
else
{
player.Play();
ConnectToDatabase();
MySqlCommand cmd = new MySqlCommand("Select Name, LPN From visitors Where password = @password;", conn);
cmd.Parameters.AddWithValue("@password", decodeStr);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if(reader["password"].ToString() == decodeStr){
//this is the problem here..
}
MessageBox.Show("he");
name = reader["Name"].ToString();
lpn = reader["LPN"].ToString();
}
CheckForIllegalCrossThreadCalls = false;
//reader.Close();
videoStream.Stop();
this.Hide(); // closes the Form2 instance.
Application.Run(new VisitorData());
}
尝试下面的代码:将您的连接字符串放入此代码中
if (decodeStr == null)
{
MessageBox.Show("There is no QR Code!");
}
else
{
player.Play();
MySqlConnection connection;
string cs = @"server=server ip;userid=username;password=userpass;database=databse";
connection = new MySqlConnection(cs);
connection.Open();
MySqlCommand command = new MySqlCommand();
string SQL = "Select Name, LPN From visitors Where password = @password";
command.CommandText = SQL;
command.Parameters.Add("@password", decodeStr);
command.Connection = connection;
command.ExecuteNonQuery();
connection.Close();
var reader = command.ExecuteReader();
while (reader.Read())
{
MessageBox.Show("he");
name = reader["Name"].ToString();
lpn = reader["LPN"].ToString();
}
CheckForIllegalCrossThreadCalls = false;
//reader.Close();
videoStream.Stop();
this.Hide(); // closes the Form2 instance.
Application.Run(new VisitorData());
}
尝试下面的代码:将您的连接字符串放入此代码中
if (decodeStr == null)
{
MessageBox.Show("There is no QR Code!");
}
else
{
player.Play();
MySqlConnection connection;
string cs = @"server=server ip;userid=username;password=userpass;database=databse";
connection = new MySqlConnection(cs);
connection.Open();
MySqlCommand command = new MySqlCommand();
string SQL = "Select Name, LPN From visitors Where password = @password";
command.CommandText = SQL;
command.Parameters.Add("@password", decodeStr);
command.Connection = connection;
command.ExecuteNonQuery();
connection.Close();
var reader = command.ExecuteReader();
while (reader.Read())
{
MessageBox.Show("he");
name = reader["Name"].ToString();
lpn = reader["LPN"].ToString();
}
CheckForIllegalCrossThreadCalls = false;
//reader.Close();
videoStream.Stop();
this.Hide(); // closes the Form2 instance.
Application.Run(new VisitorData());
}
验证标准是什么?哪个变量是QR码?能否成功连接数据库?decodeStr是存储QR码的变量。我想显示错误消息,如果mySQLyes数据库中没有数据,我可以连接,验证标准是什么?哪个变量是QR码?能否成功连接数据库?decodeStr是存储QR码的变量。如果mySQLyes数据库中没有可以连接的数据,我想显示错误消息,但我想在我的sql连接中进行验证。因为所有二维码都有值。但是数据库中只有一些qrcode匹配。但是我想在我的sql连接中进行验证。因为所有二维码都有值。但数据库中只有一些qrcode匹配。