初学者想要一个VS2010中以C#编写的windows窗体应用程序登录的代码。

如题所述

就登录的代码:
数据库连接代码放在
public partial class Studentdenglu : Form
{
SqlConnection conn = new SqlConnection("Data Source=localhost;Database=studentIn;Persist Security Info=True;UID=sa;PWD=123");数据库连接字符串
int PasswordErrorCount = 0;定义一个密码错误统计变量


在Click事件下写
private void btndenglu_Click(object sender, EventArgs e)
{
if (txtuserid.Text == "")
{
MessageBox.Show("用户ID不能为空", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
else if (txtpwd.Text == "")
{
MessageBox.Show("密码不能为空", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
else
{
DataSet dd = new DataSet();
string sql = "select * from manager where zhanghao='" + txtuserid.Text + "'and password='" + txtpwd.Text + "' ;
SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
cmd.Fill(dd);
if (dd.Tables[0].Rows.Count == 0)
{
if (++PasswordErrorCount >= 3)
{

MessageBox.Show("密码错误三次,被迫退出");
this.Close();
}
else
{
MessageBox.Show("输入的密码错误,您已错误" + PasswordErrorCount + "次。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
this.txtuserid.Focus();
cbosf.Text = "";
this.txtuserid.Text = "";
this.txtpwd.Text = "";

}

}
else

{
MessageBox.Show("登陆成功!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
}
}
}

}
温馨提示:答案为网友推荐,仅供参考