1做了一个留言本,当以管理员的身份进入后删除某个留言的时候出现如下错误:
"未将对象引用设置到对象的实例。" 这是什么原因? 在出现此原因后 你后退一步,再按下F5 刷新一下
刚才的留言又确实的被删除了 这到底是什么原因哦,搞了半天搞不明白,请知道的人指点下 谢谢!2 当我删除了某人的留言以后 我发现我连他 的ID 也给删除了,我只想删除他的流言内容,不想删除他的ID 
这个SQL 语句应该怎么写呢??

解决方案 »

  1.   

    你的意思是不删除某一行,而是删除某一行中某一列的数据
    用update好了,设置那个单元格的内容为空或者是自定义的数据.
      

  2.   

    indes.aspx页面
    public partial class _Default : System.Web.UI.Page 
    {
        string curpage;    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.lblPageCur.Text = "1";
                datagirdbind();
            }
            
        }
        public void datagirdbind()
        {
            curpage = this.lblPageCur.Text;
            SqlConnection conn = Bk.coumm();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from tb_Visitor";
            cmd.Connection = conn;
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataSet ds = new DataSet();
            sda.Fill(ds, "tb_Visitor");
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            pds.PageSize =5;
            pds.DataSource = ds.Tables["tb_Visitor"].DefaultView;
            pds.CurrentPageIndex = Convert.ToInt32(curpage) - 1;
            this.Button1.Enabled = true;
            this.Button2.Enabled = true;
            if (curpage == "1")
            {
                this.Button1.Enabled = false;
            }
            if (curpage == pds.PageCount.ToString())
            {
                this.Button2.Enabled = false;
            }
            
            this.DataList1.DataSource = pds;
            this.DataList1.DataBind();
        }    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            LinkButton dele = (LinkButton)e.Item.FindControl("lbtnDelete");
            if (dele != null)
            {
                dele.Attributes.Add("Onclick", "return confirm('确定删除吗?')");
            }
        }
        protected void lbtnDelete_Command(object sender, CommandEventArgs e)
        {
            if (Session["tb_Admin"] != null)
            {
                
                string userID = e.CommandArgument.ToString();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = Bk.coumm();
                cmd.CommandText = "delete from tb_Visitor where VisitorID='" + userID + "'";
                if (cmd.ExecuteNonQuery() > 0)
                {
                    Response.Redirect("info.aspx?message =删除成功");
                }
                else
                {
                    Response.Redirect("info.aspx?message =删除失败");
                }        }
            else
            {
                Response.Redirect("info.aspx?message=对不起,只有管理员才允许删除留言,如果你是管理员,请先登陆");
            }    }
        protected void lbtnReply_Command(object sender, CommandEventArgs e)
        {
            if (Session["tb_Admin"] != null)
            {
                
                string userID = e.CommandArgument.ToString();
                Response.Redirect("reply.aspx?userID=" + userID + "");
            }
            else
            {
                Response.Redirect("info.aspx?message=对不起,只有管理员才允许回复留言,如果你是管理员,请先登陆");
            }
        }    protected void Button3_Click(object sender, EventArgs e)
        {
            this.lblPageCur.Text = "1";
            datagirdbind();
        }    protected void Button1_Click1(object sender, EventArgs e)
        {
            this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) - 1);
            datagirdbind();
        }
        protected void Button2_Click1(object sender, EventArgs e)
        {
            this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) + 1);
            datagirdbind();
        }
        protected void Button3_Click1(object sender, EventArgs e)
        {
            this.lblPageCur.Text = "1";
            datagirdbind();
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            this.lblPageCur.Text = this.lblPageTotal.Text;
            datagirdbind();
        }info.aspx 页面public partial class info : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Label1.Text = Request.QueryString["message"].Replace("先登陆","先<a href=login.aspx>登陆</a>");    }
    }
      

  3.   

    info.aspx?message   =删除成功 
    将问号后的去掉.
      

  4.   

    cmd.CommandText   =   "delete   from   tb_Visitor   where   VisitorID= ' "   +   userID   +   " ' "; 
    //首先确定你的逻辑是否正确
    Response.Write("delete   from   tb_Visitor   where   VisitorID= ' "   +   userID   +   " ' ");
    Response.End();
    把这条sql语句放到查询分析器里用一下,看看是不是也删除了用户ID
    另外你确定VisitorID是字符类型的字段吗?还有userID是字符型的吗?如果不是用"+userID+"啊,先把userID类型转换为int型的。