第一次用参数写登陆代码。。。
首先是DAL层:
- C# code
public bool Login(UserModel um) { bool flag = false; string sql = "select * from User where UserName=@username"; SqlParameter[] paras = new SqlParameter[]{ new SqlParameter("username",um.UserName), new SqlParameter("userpwd",um.UserPwd), new SqlParameter("departmentname",um.DepartMentName) }; int res = sqlhelper.CheckLogin(sql,paras,CommandType.Text); if (res > 0) { flag = true; } return flag; }
怎么写sqlhelper.CheckLogin这个方法完成登录呢,要对密码和DepartMentName都要验证的过程。。。一用参数就不会做了。。。拜托各位了
------解决方案--------------------------------------------------------
- C# code
public bool Login(UserModel um) { bool flag = false; string sql = "select * from User where UserName=@username And userpwd=@userpwd And departmentname=@departmentname"; SqlParameter[] paras = new SqlParameter[]{ new SqlParameter("@username",um.UserName), new SqlParameter("@userpwd",um.UserPwd), new SqlParameter("@departmentname",um.DepartMentName) }; int res = sqlhelper.CheckLogin(sql,paras,CommandType.Text); if (res > 0) { flag = true; } return flag; }