Home > database >  "System. InvalidOperationException" type of untreated anomaly in MySql. The Data. The DLL.
"System. InvalidOperationException" type of untreated anomaly in MySql. The Data. The DLL.

Time:09-26


//create a database connection function
Public MySqlConnection GetConn ()
{
String connString="server=localhost; The username=root; Password=111222333; The database=CSF ";
MySqlConnection conn=new MySqlConnection (connString);

Try
{
Conn. The Open ();
}
The catch (Exception ex)
{
MessageBox. Show (ex. ToString ());
}
return conn;
}


Private void button1_Click (object sender, EventArgs e)
{
If (textBox1. Text=="" | | textBox2. Text==" ")
{
MessageBox. Show (" the user name or password can't be empty ");
return;
}
The else
{
MySqlConnection conn=GetConn ();
MySqlCommand cmd1=new MySqlCommand (" select the username, userpassword from the userInfo where username='" +
TextBox1. Text. The Trim () + "' and userpassword='" + textBox2. Text. The Trim () +"' ", conn);
Conn. The Open ();//display error
MySqlDataReader Dr=cmd1. ExecuteReader ();
While (Dr. Read ())
{
The login _instance=new login ();
The userName=textBox1. Text;
String password=textBox2. Text;
Enclosing the Visible=false;
MessageBox. Show (" login success ");
MainCenter MC=new mainCenter ();
MC. The Show ();

Conn. Close ();
return;
}

If (Dr. Read ()==false)
{
Conn. Close ();
MessageBox. Show (" the user name or password is not correct ");
}
}
}

CodePudding user response:

Pay attention to the errors the last layer, database account verification error, the method is not supported, check the MYSQL database version, and the machine CONNECTOR version are consistent,

CodePudding user response:

The dalai! Version is caused by inconsistent error! Thank you very much!
  • Related