表现层:
- VB.NET code
if (BLL.Users.CheckUser("张三", "123").Read()) { Response.Write("登录成功!"); } else { Response.Write("登录失败!"); }
BLL层:
- VB.NET code
/// <summary> /// 是否存在该记录 /// </summary> public static SqlDataReader CheckUser(string uName, string uPwd) { return SQLServerDAL.Users.CheckUser(uName, uPwd); }
DAL层:
/// <summary>
/// 是否存在该记录
/// </summary>
public static SqlDataReader CheckUser(string uName, string uPwd)
{
SqlParameter[] parameters = {
new SqlParameter("@userName", SqlDbType.NVarChar,50,uName),
new SqlParameter("@userPwd", SqlDbType.NVarChar,50,uPwd)
};
//return Class1.RunProcedure("CheckUser", parameters);
return SqlHelper.ExecuteReader(CommandType.StoredProcedure, "CheckUser", parameters);
}
SQLHelper:
- VB.NET code
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)//设置断点看过N次了,commandParameters有值 { SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(ConnectionStringLocalTransaction); // we use a try/catch here because if the method throws an exception we want to // close the connection throw code, because no datareader will exist, hence the // commandBehaviour.CloseConnection will not work try { PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);//断点到这里一看rdr=null;!!直接跳到Catch了!!! cmd.Parameters.Clear(); return rdr; } catch { conn.Close(); throw; } }
求各位大侠帮忙!到底怎么回事!都有参数啊!干嘛老是报未提供参数!!!!!烦死了!T.T
------解决方案--------------------------------------------------------
都没见到你给parameters赋值,当然让你提供参数了。传两个null进去算怎么回事。。