本帖最后由 茹化肖 于 2013-11-21 16:04 编辑
- <div class="blockcode"><blockquote>UI层的代码
- protected void btnlogin_Click(object sender, EventArgs e)
- {
- UserInfo user = new UserInfo();
- user.UserName = txtusername.Text.Trim();
- user.UserPwd = Txtpwd.Text.Trim();
- if (!BLL.LoginCheck(user))
- {
- Response.Write("<script>alert('Username or Pwd ERROR!');</script>");
- }
- else
- {
- Response.Write("<script>alert('success!');</script>");
- Response.Redirect("~/UIQ/Contentlist1.aspx");
- }
复制代码 /// <summary>
///BLL 业务逻辑层,静态方法,
/// </summary>
public class BLL
{
//登陆查询是否存在该用户
public static bool LoginCheck(UserInfo user)
{
DAL dal = new DAL();
if (user.UserName == "" || user.UserPwd == "")
return false;
else
{
if ((int)dal.SelectByName(user) > 0)//这句报错 ,dal 的值为NULL
return true;
else
return false;
}
}
}下面给另外 selectByName 的代码- public object SelectByName(UserInfo user)
- {
- string sql = string.Format("select count(*) from UserInfo where username={0}", user.UserName);
- return SqlHelper.ExecuteScalar(sql);
- }
复制代码 下面是 sqlHelper 的代码- public static object ExecuteScalar(string sql, params SqlParameter[] cmdParams)//查询返回第一行第一列 object
- {
- SqlCommand cmd = new SqlCommand(sql, conn);
- foreach (SqlParameter parm in cmdParams)
- {
- cmd.Parameters.Add(parm);
- }
- try
- {
- conn.Open();
- object o = cmd.ExecuteScalar();
- return o;
- }
- catch
- {
- return null;
- }
- finally
- {
- cmd.Dispose();
- conn.Close();
- conn.Dispose();
- }
- }
复制代码 请各位给指导下 这个值为null 的时候 怎么排错?
|