关于登陆判断的函数如何写?c#。

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:08:43
表示这样的:
ID NAME PASSWORD
1 小王 123
2 小李 456
3 小赵 789
现在要判断用户名是否在这里,如果在这里在判断密码是否相等。
函数为这样结构:
返回值 函数名(用户名,密码)
{
}
如果相符,返回true,不相符返回false。

public bool aa(string i,string j)
{
try
{
//这里写连接数据库的语句,或者你建个类里面连接数据库,我注释的部分假//设已经连接好数据库了
//SqlConnection con=new SqlConnection("server=;uid=;pad=;//database=");
SqlCommand cmd=new SqlCommand("select count(*) from 表名 where name='"+nameTXT.text+"',password='"+passworedTXT+"'",con);
string k=null;
bool o=false;
k=cmd.cmd.ExecuteScalar().ToString();
if(k=="1")
{
o=true;
}
else
{
o=false;
}
}
catch()
{
o=false;
}
return o;
}
//我不是在环境打的,就这么打的,有些关键字可能不正确,大概就是这意思

很简单
用一个SQL语句~
SqlCommand cmd=new SqlCommand("select count(*) from youtable where ID=你输入的ID and Name=你输入的姓名and Password=你输入的密码")

然后
int t=cmd.ExecuteScalar().ToString();
//如果有的话 t=1 如果没有 t=0
你可以做出来了
接分

//计算登陆次数
int count = 0;
private void In_Click(object sender, E