string user = textBox1.Text;
string password = textBox2.Text;
string str = "server=localhost;database=账号密码;uid=root;pwd=123789;Charset=utf8";
MySqlConnection conn = new MySqlConnection(str);
conn.Open();
if (textBox1.Equals(null) && textBox2.Equals(null))
{
MessageBox.Show("请输入账号密码");
}
else
{
string sql = "select * from test where user='" + user + "'and password=" + password + "'";
MySqlCommand cmd = new MySqlCommand(sql, conn)
{
CommandType = CommandType.Text
};
这里错了 MySqlDataReader sdr = cmd.ExecuteReader();
(报错为MySql.Data.MySqlClient.MySqlException)
if (sdr.Read())
{
MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("登录失败");
}
}
}