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

Object reference not set to an instance of an object.

我做的网站在本地测试都是好的 一切正常 但是发布到网站上去的时候就出现了Object reference not set to an instance of an object. 这个问题 
前台html

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Customer_More.aspx.cs" Inherits="News_more" %>
<%@ Register Src="Controllers/Bottom.ascx" TagName="Bottom" TagPrefix="uc4" %>
<%@ Register Src="Controllers/Top.ascx" TagName="Top" TagPrefix="uc1" %>
<%@ Register Src="Controllers/Left.ascx" TagName="Left" TagPrefix="uc2" %>
<html>
<head>
<title><%=Titlep %></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta content="<%= Descriptionp%>" name="description"/>
<meta content="<%=Keywordsp %>" name="keywords" />
<link href="Images/css.css" rel="stylesheet" type="text/css" />
</head>
<body style="text-align: center">
<form id=form1 runat=server>
    <table border="0" align="center" cellpadding="0" cellspacing="0" style="width: 778px">
        <tr>
            <td style="width: 100px">
                <uc1:Top ID="Top1" runat="server" />
            </td>
        </tr>
</table>
    <table border="0" align="center" cellpadding="0" cellspacing="0" style="width: 778px; background-color: #ffffff;">
        <tr>
            <td style="height: 395px">
                <table border="0" cellpadding="0" cellspacing="0" style="width: 778px">
                    <tr>
                      <td width="183" align="left"><div align="left">
                        <uc2:Left ID="Left1" runat="server" />
                      </div></td>
                        <td width="595" valign="top"><div align="center"> 
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td> </td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td><img src="Images/a4.jpg" width="585" height="37"></td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td style="height: 115px"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><center><asp:Label ID="Ltitle" runat="server" Text="标题"></asp:Label></center></td>
                </tr>
                <tr>
                  <td style="height: 4px"> <asp:Label ID="Lcontent" runat="server" Text="内容"></asp:Label></td>
                </tr>
              </table></td>
            </tr>
          </table>
  </div>
                      </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
                <uc4:Bottom ID="Bottom1" runat="server" />
            </td>
        </tr>
</table></form>
</body>
</html>


.cs代码
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    public string Titlep="1";
    public string Descriptionp="2";
    public string Keywordsp="3";
    protected void Page_Load(object sender, EventArgs e)
    {
        this.BindToList();
        
    }
    private void BindToList()
    {

        //title,des,con
        GetContent drt = new GetContent();
        OleDbDataReader drf = drt.GetTDC();
        if(drf.Read())
        {
          
           // this.Titlep=Request.QueryString["Title"]; 
          //  this.Descriptionp=Request.QueryString["Description"];
           // this.Keywordsp=Request.QueryString["Keywords"];
            this.Titlep = drf["Title"].ToString();
            this.Descriptionp = drf["Description"].ToString();
            this.Keywordsp = drf["Keywords"].ToString();
        }
        drf.Close();

        //品牌
        GetContent getb = new GetContent();
        OleDbDataReader drb = getb.GetMrjp();
        this.GridList1.DataSource = drb;
       // this.DataGrid1.DataSource = drb;
        //this.DataGrid1.DataBind();
       this.GridList1.DataBind();
        drb.Close();

        GetContent geta = new GetContent();
        OleDbDataReader dra = geta.GetTzrm();
        this.GridList2.DataSource = dra;
        this.GridList2.DataBind();
        //this.DataGrid2.DataSource = drb;
        //this.DataGrid2.DataBind();
        dra.Close();
        //新闻列表
        GetContent gettop = new GetContent();
        OleDbDataReader drnt = gettop.GetNewsTop();
        this.GridList.DataSource = drnt;
        this.GridList.DataBind();
        drnt.Close();
        //大图片
        GetContent getnewstop = new GetContent();
        OleDbDataReader dr = getnewstop.GetNewsImagesTop();
        while (dr.Read())
        {
            //this.Image1.ImageUrl = "Upload/" + dr["img"].ToString();
           //this.HyperLink1.Text = dr["title"].ToString();
           // this.HyperLink1.NavigateUrl = "news_more.aspx?id=" + dr["id"].ToString();
        }
        dr.Close();
        
    }
    protected void GridList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
类文件部分代码
 public OleDbDataReader GetTDC()
    {
        OleDbHelper.OleDbHelper helper = new OleDbHelper.OleDbHelper();
        OleDbDataReader dr;
        helper.RunCmd("select * from title", out dr);
        return (dr);
    }
大虾们救我啊  急等 --------------------编程问答-------------------- 空引用.. --------------------编程问答-------------------- http://www.diybl.com/course/4_webprogram/asp.net/netjs/20090313/161332.html --------------------编程问答-------------------- 哈哈,我刚发布一个网站出现了这个问题,解决了! --------------------编程问答-------------------- 这个是权限问题,你得给你这个网站文件夹或是你用到的文件夹分权限 --------------------编程问答-------------------- 要看哪一行出错,有可能的是取数据的方法内部出了异常,给catch掉了,然后返回一个空的对象。 --------------------编程问答-------------------- 不是你的Request.QueryString是NULL就是你的数据表里的数据是null --------------------编程问答--------------------


同样的问题,大家看看啊

“我做的网站在本地测试都是好的 一切正常 但是发布到网站上去的时候就出现了Object reference not set to an instance of an object. 这个问题 ” --------------------编程问答-------------------- 数据库链接正常么?有该ip地址么?
我前几天发布就犯了这个低级错误 --------------------编程问答-------------------- 你能确保你的 trans 又实例化?

你肯定连接都没打开

catch(Exception ex) {
if(trans != null) {
trans.Rollback();
}
throw;
} --------------------编程问答-------------------- 我滴天代码这么长 --------------------编程问答--------------------
引用 7 楼 pyrotechnist 的回复:
同样的问题,大家看看啊

“我做的网站在本地测试都是好的 一切正常 但是发布到网站上去的时候就出现了Object reference not set to an instance of an object. 这个问题 ”


你的PublicGetDB.ExecData()方法里有空引用~ --------------------编程问答-------------------- 楼主看看黄页上的堆栈信息~,最后调用的是哪个方法报错了。 --------------------编程问答-------------------- 还是不太懂<a href='http://www.baidu.com'>还是百度吧</a> --------------------编程问答-------------------- <a href="http://www.diybl.com/course/4_webprogram/asp.net/netjs/20090313/161332.html" target="_blank" >http://www.diybl.com/course/4_webprogram/asp.net/netjs/20090313/161332.html</a>这是什么呀
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,