100分的问题:用户代码未处理 System.NullReferenceException Message="未将对象引用设置到对象的实例。" 本帖最后由 yanxinjia 于 2011-02-18 17:16:02 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 异常消息为:用户代码未处理 System.NullReferenceException Message="未将对象引用设置到对象的实例。" Source="WebApplication1" StackTrace: 在 WebApplication1.DBHelp.ExcuteDataSet(String sql, CommandType type, SqlParameter[] parms) 位置 D:\DataProc\WebApplication1\WebApplication1\DBProc.cs:行号 147 在 WebApplication1.Default.Page_Load(Object sender, EventArgs e) 位置 D:\DataProc\WebApplication1\WebApplication1\Default.aspx.cs:行号 75 在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) 在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) 在 System.Web.UI.Control.OnLoad(EventArgs e) 在 System.Web.UI.Control.LoadRecursive() 在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException: Response.Write("<script>window.alert('" + "GetMaxTZYM" + "')</script>"); 是不是用了updatepanel ds.Tables[0]. 空引用看看你得sql 查处数据来没 你调用这个方法了吗public int GetMaxTZYM()在哪调的? Response.Write("<script>alert('GetMaxTZYM');</script>"); 如果没使用UpdatePanel的话是可行的。异常信息是:DataSet ds = DBHelp.ExcuteDataSet(sql, CommandType.Text, null);返回的ds为null string sql = "select max(tzyy*100+tzmm) tzym from dwtz"; DataSet ds = DBHelp.ExcuteDataSet(sql, CommandType.Text, null);if(ds!=null &&ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0) { i = int.Parse(ds.Tables[0].Rows[0]["tzym"].ToString()); } ds 对象的没有得到, 导致ds对象为空, 就出错了 如果空不是你预期的结果那么就要好的检查 DBHelp.ExcuteDataSet(sql, CommandType.Text, null)这句它确保它不是null反之应处理空的值如上面提到的if(ds!=null &&ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0) { i = int.Parse(ds.Tables[0].Rows[0]["tzym"].ToString()); } DataSet ds = DBHelp.ExcuteDataSet(sql, CommandType.Text, null);这里加上if(ds!=null){ if (ds.Tables[0].Rows.Count > 0) { i = int.Parse(ds.Tables[0].Rows[0]["tzym"].ToString()); }} return i; asp.net listview 如何用程序控制textbox里的默认值呀,谢了 请教特殊的字符串组合 这种效果如何实现呢? 图片代替提交按钮 从一个表中取出数据添加到另一个表中(access),出了错!!!请大家帮助!!! DropDownList的SelectedIndexChanged事件 有请星级的高手及诸控件高手们解决一下问题 求教,程序部署后文件不能正常上传到服务器上? 各位大侠,请问在asp.net 中如何调用 api 函数? asp.net与xml的关系 ASPxGridViewTemplateReplacement这个东东在哪里 在线聊天
Source="WebApplication1"
StackTrace:
在 WebApplication1.DBHelp.ExcuteDataSet(String sql, CommandType type, SqlParameter[] parms) 位置 D:\DataProc\WebApplication1\WebApplication1\DBProc.cs:行号 147
在 WebApplication1.Default.Page_Load(Object sender, EventArgs e) 位置 D:\DataProc\WebApplication1\WebApplication1\Default.aspx.cs:行号 75
在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
在 System.Web.UI.Control.OnLoad(EventArgs e)
在 System.Web.UI.Control.LoadRecursive()
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
如果没使用UpdatePanel的话是可行的。异常信息是:
DataSet ds = DBHelp.ExcuteDataSet(sql, CommandType.Text, null);
返回的ds为null
DataSet ds = DBHelp.ExcuteDataSet(sql, CommandType.Text, null);
if(ds!=null &&ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0)
{
i = int.Parse(ds.Tables[0].Rows[0]["tzym"].ToString());
}
反之应处理空的值如上面提到的
if(ds!=null &&ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0)
{
i = int.Parse(ds.Tables[0].Rows[0]["tzym"].ToString());
}
DataSet ds = DBHelp.ExcuteDataSet(sql, CommandType.Text, null);
这里加上
if(ds!=null){ if (ds.Tables[0].Rows.Count > 0)
{
i = int.Parse(ds.Tables[0].Rows[0]["tzym"].ToString());
}
} return i;