//创建数据库连接的函数
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("用户名或密码不正确");
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货