

//創建資料庫連接的函式
public MySqlConnection GetConn()
{
string connString = "server=localhost;username=root;password=111222333;database=csf";
MySqlConnection conn = new MySqlConnection(connString);
try
{
conn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return conn;
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text==""||textBox2.Text=="")
{
MessageBox.Show("用戶名或密碼不能為空");
return;
}
else
{
MySqlConnection conn = GetConn();
MySqlCommand cmd1 = new MySqlCommand("select username,userpassword from userInfo where username='" +
textBox1.Text.Trim()+ "' and userpassword='" + textBox2.Text.Trim() + "'",conn);
conn.Open(); //顯示錯誤
MySqlDataReader dr = cmd1.ExecuteReader();
while(dr.Read())
{
login _instance=new login();
userName = textBox1.Text;
string password = textBox2.Text;
this.Visible = false;
MessageBox.Show("登陸成功");
mainCenter mc=new mainCenter();
mc.Show();
conn.Close();
return;
}
if (dr.Read() == false)
{
conn.Close();
MessageBox.Show("用戶名或密碼不正確");
}
}
}
uj5u.com熱心網友回復:
注意最后一層的錯誤提示,資料庫賬號驗證出錯,方法不支持,檢查一下MYSQL資料庫的版本和本機的CONNECTOR版本是否一致。uj5u.com熱心網友回復:
對噠!是版本不一致導致的錯誤!謝謝!轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/79498.html
標籤:MySQL
下一篇:vf中控制頁眉
