标题:用户代码NullReferenceException未将对象引用设置到对象的实例
取消只看楼主
董晓云
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-4-5
结帖率:42.86%
 问题点数:0 回复次数:0 
用户代码NullReferenceException未将对象引用设置到对象的实例
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
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;

namespace xueshengtonzhi
{
    public partial class detail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack )
                DataGridDataBind();

        }
        protected void DataGridDataBind()
        {
            string ID = "";
            if (Request["ID"].ToString()!=null)
            {
                ID = Request["ID"].ToString();//取得上以页面传递过来的参数
            }
            
            SqlConnection conn = new SqlConnection("server=127.0.0.1;uid=sa;pwd=1234;database=xiwangzhan");
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from xstzb where id=" + ID, conn);
            //打开数据连接
            //创建数据读取器
            try
            {
                SqlDataReader dr = cmd.ExecuteReader();
                //如果取到数据
                if (dr.Read())
                {
                    head.Text = dr["Title"].ToString();
                    content.Text = dr["Content"].ToString();
                    man.Text = dr["Publicman"].ToString();
                    riqi.Text = Convert.ToDateTime(dr["Publictime"]).ToString();
                }

            }
            catch (Exception error)
            {
                Response.Write(error.ToString());
            }
            finally{
                //关闭数据连接
                conn.Close();
            }
        运行时出现户代码NullReferenceException未将对象引用设置到对象的实例,各位高手帮忙看看哪有问题?谢谢啦!
搜索更多相关主题的帖子: 实例 对象 代码 用户 
2010-04-22 09:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-303982-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040005 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved