C#登陆界面与数据库中的用户名和密码进行检查
private void btnlogin_Click(object sender, EventArgs e)
{
if (txtname == null)
{
MessageBox.Show("请输入用户名","登录界面");
}
else if (txtpw == null)
{
MessageBox.Show("请输入密码", "登录界面");
}
string sql =string.Format( "select count(*) from usera where userid='{0}' and userpw='{1}'",txtname.Text.Trim(),txtpw.Text.Trim());
SqlCommand cmd = new SqlCommand(sql, DbCon.Conn);
DbCon.Conn.Open();
int count = (int)cmd.ExecuteScalar();
DbCon.Conn.Close();
if (count == 1)
{
Main Mf = new Main();
Mf.Show();
this.Hide();//隐藏此窗口
}
else
{
MessageBox.Show("账号或密码错误!请确认后重新输入", "登录界面");
}
}
posted on 2010-03-25 15:10 shamanter 阅读(2604) 评论(0) 编辑 收藏 举报