当前位置:编程学习 > C#/ASP.NET >>

问一个大家可能忽视的问题哦

我现在正在做一个论坛,可是发表主题的页面出了问题,当点击发表按钮的时候,内容全到插到数据库里了,可就是重定向到我的主题页面时,它会显示错误,如果不重定向的话,发表时就没有任何错误,但是不能返回主题页!!郁闷啊各位大哥,帮帮忙解决啊!!说一下!!我是通过主页的datagrid传值的


错误如下:异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误: 


行 69:  {
行 70: 
行 71:  string boardID=Request.QueryString["boardID"].ToString();
行 72:  Session["boardID"]=boardID;
行 73: 
 
--------------------编程问答-------------------- 不好意思,刚刚没发全:具体如下:
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误: 


行 69:  {
行 70: 
行 71:  string boardID=Request.QueryString["boardID"].ToString();
行 72:  Session["boardID"]=boardID;
行 73:  this.DataGrid1.DataSource=operate.selectTheme(Session["boardID"].ToString());
 
--------------------编程问答-------------------- 检查Request.QueryString["boardID"]是否为null --------------------编程问答-------------------- 错误信息里边有错误行号,贴出来。

你先自己调试一下,说出具体是哪一个对象在运行时出的错。 --------------------编程问答-------------------- 重定向的时候没有把boardID加上去? --------------------编程问答--------------------
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误: 


行 33:  if(!this.IsPostBack)
行 34:  {
行 35:  string boardID=Request.QueryString["boardID"].ToString();
行 36:  Session["boardID"]=boardID;
行 37:  this.dataBindToDatagrid();
第35行出现错误!!
 

我在发表按钮里写的代码如下:

string boardID=Session["boardID"].ToString();
string title=this.txtTheme.Text.Trim();
    Session["title"]=title;
string content=this.txtContent.Text;
string replyNum="0";
string postUserName=Session["userName"].ToString();
System.DateTime postDate=System.DateTime.Now;
System.DateTime lastPostTime=System.DateTime.Now;
string hits="0";
                operate.insertTheme(title,content,boardID,replyNum,postUserName,postDate,hits,lastPostTime);
    Response.Redirect("forumThreads.aspx");
--------------------编程问答-------------------- 大家帮我看看好吗?
急啊拜托了 --------------------编程问答-------------------- 先判断一下Session["boardID"]=boardID;是否存在

if(session["xxx"]!="")
{
string boardID=Session["boardID"].ToString();
string title=this.txtTheme.Text.Trim();
    Session["title"]=title;
string content=this.txtContent.Text;
string replyNum="0";
string postUserName=Session["userName"].ToString();
System.DateTime postDate=System.DateTime.Now;
System.DateTime lastPostTime=System.DateTime.Now;
string hits="0";
                operate.insertTheme(title,content,boardID,replyNum,postUserName,postDate,hits,lastPostTime);
    Response.Redirect("forumThreads.aspx");

} --------------------编程问答-------------------- string boardID=Request.QueryString["boardID"].ToString();


boardID参数没写错吧……

if(Request["boardID"]!=null)
{
行 35: string boardID=Request.QueryString["boardID"].ToString();
行 36: Session["boardID"]=boardID;
行 37: this.dataBindToDatagrid();
} --------------------编程问答-------------------- Response.Redirect("forumThreads.aspx?boardID="+boardID); --------------------编程问答-------------------- operate.selectTheme(Session["boardID"].ToString());
这个没有返回值,所以报错

楼上的方法是可以了
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,