“/DriverSystem”应用程序中的服务器错误。异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 行 198: //}
行 199:
行 200: return (int)paramCache[3].Value;
行 201: }
行 202:
源文件: h:\毕业设计\基于.NET的驾校理论考试模拟系统\DriverSystem\App_Code\Include\UserDB.cs 行: 200 堆栈跟踪: [NullReferenceException: 未将对象引用设置到对象的实例。]
DriverSystem.Include.UserDB.AddUser(String sUserName, String sPassword, String sEmail) in h:\毕业设计\基于.NET的驾校理论考试模拟系统\DriverSystem\App_Code\Include\UserDB.cs:200
DriverSystem.Admins.UserRegister.SureBtn_Click(Object sender, EventArgs e) in h:\毕业设计\基于.NET的驾校理论考试模拟系统\DriverSystem\UserRegister.aspx.cs:55
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.5448; ASP.NET 版本:2.0.50727.5420
AddUser的代码如下:
public int AddUser(String sUserName,String sPassword,String sEmail)
{
//定义数据库的Connection and Command
SqlConnection myConnection = new SqlConnection(SQLHelper.SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_AddUser", myConnection);
//定义访问数据库的方式为存储过程
myCommand.CommandType = CommandType.StoredProcedure; //创建访问数据库的参数
SqlParameter[] paramCache = SQLHelper.SQLHelper.GetCachedParameters(paramAddUser);
if (paramCache == null)
{
paramCache = new SqlParameter[]{
new SqlParameter("@UserName",SqlDbType.VarChar),
new SqlParameter("@Password",SqlDbType.VarChar),
new SqlParameter("@Email",SqlDbType.VarChar),
new SqlParameter("@UserId",SqlDbType.Int,4)};
SQLHelper.SQLHelper.CacheParameters(paramAddUser, paramCache);
}
SQLHelper.SQLHelper.AddMyCommandParams(myCommand, paramCache);
paramCache[0].Value = sUserName;
paramCache[1].Value = sPassword;
paramCache[2].Value = sEmail;
paramCache[3].Direction = ParameterDirection.ReturnValue; try
{
if (myConnection.State == ConnectionState.Closed)
{
//打开数据库的连接
myConnection.Open();
}
}
catch (Exception ex)
{
Console.WriteLine("数据库连接失败!:" + ex.Message);
}
finally
{
if (myConnection.State == ConnectionState.Open)
{
//关闭数据库的连接
myConnection.Close();
}
}
try
{
//执行数据库的存储过程(访问数据库)
myCommand.ExecuteReader();
}
catch (Exception ex)
{
Console.WriteLine("数据库连接失败!:" + ex.Message);
} return (int)paramCache[3].Value;
}
各位大侠救救我这小菜鸟吧,快被这个问题搞昏了......
行 199:
行 200: return (int)paramCache[3].Value;
行 201: }
行 202:
源文件: h:\毕业设计\基于.NET的驾校理论考试模拟系统\DriverSystem\App_Code\Include\UserDB.cs 行: 200 堆栈跟踪: [NullReferenceException: 未将对象引用设置到对象的实例。]
DriverSystem.Include.UserDB.AddUser(String sUserName, String sPassword, String sEmail) in h:\毕业设计\基于.NET的驾校理论考试模拟系统\DriverSystem\App_Code\Include\UserDB.cs:200
DriverSystem.Admins.UserRegister.SureBtn_Click(Object sender, EventArgs e) in h:\毕业设计\基于.NET的驾校理论考试模拟系统\DriverSystem\UserRegister.aspx.cs:55
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.5448; ASP.NET 版本:2.0.50727.5420
AddUser的代码如下:
public int AddUser(String sUserName,String sPassword,String sEmail)
{
//定义数据库的Connection and Command
SqlConnection myConnection = new SqlConnection(SQLHelper.SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_AddUser", myConnection);
//定义访问数据库的方式为存储过程
myCommand.CommandType = CommandType.StoredProcedure; //创建访问数据库的参数
SqlParameter[] paramCache = SQLHelper.SQLHelper.GetCachedParameters(paramAddUser);
if (paramCache == null)
{
paramCache = new SqlParameter[]{
new SqlParameter("@UserName",SqlDbType.VarChar),
new SqlParameter("@Password",SqlDbType.VarChar),
new SqlParameter("@Email",SqlDbType.VarChar),
new SqlParameter("@UserId",SqlDbType.Int,4)};
SQLHelper.SQLHelper.CacheParameters(paramAddUser, paramCache);
}
SQLHelper.SQLHelper.AddMyCommandParams(myCommand, paramCache);
paramCache[0].Value = sUserName;
paramCache[1].Value = sPassword;
paramCache[2].Value = sEmail;
paramCache[3].Direction = ParameterDirection.ReturnValue; try
{
if (myConnection.State == ConnectionState.Closed)
{
//打开数据库的连接
myConnection.Open();
}
}
catch (Exception ex)
{
Console.WriteLine("数据库连接失败!:" + ex.Message);
}
finally
{
if (myConnection.State == ConnectionState.Open)
{
//关闭数据库的连接
myConnection.Close();
}
}
try
{
//执行数据库的存储过程(访问数据库)
myCommand.ExecuteReader();
}
catch (Exception ex)
{
Console.WriteLine("数据库连接失败!:" + ex.Message);
} return (int)paramCache[3].Value;
}
各位大侠救救我这小菜鸟吧,快被这个问题搞昏了......
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货