当做出一个登录界面时,在DAL中要进行参数传递,然后写查询语句,再创建一个新的对象
然后进行判断,最后进行返回
public class UserInfoDAL
{
public static UserInfo Select(string name,string pwd)
{
var sql = "select * from UserInfo where name=@name and pwd=@pwd";
SqlParameter[] sqlParameter = {
new SqlParameter ("@name",name),
new SqlParameter ("@pwd",pwd)
};
var reader = SqlHelper.QueryReader(sql, sqlParameter);
if (reader.Read())
{
UserInfo user = new UserInfo()
{
Id = Convert.ToInt32(reader["Id"]),
Name = Convert.ToString(reader["Name"]),
Role = Convert.ToInt32(reader["Role"])
};
reader.Close();
return user;
}else
{
reader.Close();
return null;
}
}
}
然后再BLL中调用DAL的方法
public class UserInfoBLL
{
public static UserInfo Select(string name, string pwd)
{
return UserInfoDAL.Select(name, pwd);
}
}