private void btnLogin_Click(object sender, System.EventArgs e)
{
string userID=this.txtUserID.Text;
string pwd =this.txtPwd.Text;
SqlConnection conn=new SqlConnection("data source=(local);user id=sa;pwd=;initial catalog=test;integrated security=SSPI");
conn.Open();
SqlCommand cmd=new SqlCommand("select count(*) as flag from login where userID="+"'"+userID+"'"+"and pwd ="+"'"+pwd+"'",conn);
cmd.ExecuteNonQuery();
int flag=Convert.ToInt32(cmd.ExecuteScalar().ToString());
if(flag>0)
{
Form check=new check();
check.Show();
this.Hide();
}
else
{
this.label3.Enabled=true;
this.label3.Text="出错";
this.label3.Visible=true;
}
}

这篇博客展示了如何在C#中实现一个简单的登录功能。通过获取输入的用户名和密码,连接到SQL数据库进行验证。如果匹配成功,将显示新的检查页面;否则,显示错误提示。
最低0.47元/天 解锁文章
1526

被折叠的 条评论
为什么被折叠?



