关于登陆界面的验证。初学者
代码
public bool ValidateUser(string txtUser,string txtPwd,ref string message )
{
string sql = string.Format("SELECT COUNT(*) FROM User WHERE ID='{0}'AND Pwd='{1}'",txtUser , txtPwd );
try
{
// 创建command命令
SqlCommand command = new SqlCommand(sql, DBHekper.connetion);
DBHekper.connetion.Open();
int count = (int)command.ExecuteNonQuery();//统计返回值
if (count ==1)
{
return true;
}
else
{
message = "用户名或密码不存在!";
return false;;
}
}
catch (Exception ex)
{
message = "操作数据库出错";
Console.WriteLine(ex.Message);
}
finally
{
DBHekper.connetion.Close();
}
return false;
&nb