我今天做个删除单条记录。。但就删不掉。是不是greeview里面属性没有设置正确?   /// <summary>
    /// 删除单条数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>    protected void GVlist_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GVlist.DataKeys[e.RowIndex].Value.ToString();
        if(bbdel.GetDelete(int.Parse(id))>0)
        {
            this.lblshow.Text = "<script>alert('删除成功!')</script>";
            BindGreeView();
        }
    }
 /// <summary>
        /// 删除一条数据
        /// </summary>
        public int GetDelete(int Id)
        {
            string sql = "delete from Books where Id="+Id;            return DbHelperSQL.ExecuteSql(sql);
        }

解决方案 »

  1.   

    看看id是不是获取到了,调试看下sql,
      

  2.   

    你可以测试呀,点击删除,输出ID看看,看可不可以输出ID,如果可以,看看你的sql语句和sqlhelper,这也是我一般是这样调试的,看你的代码是没有错的。
      

  3.   

    你跟踪一下,看是ID没获取到,还是SQL语句有问题!
      

  4.   

    先调试看看那你id的值看看它是多少,然后看看你的数据库中这个id有没有。
      

  5.   

    string id = this.GVlist.DataKeys[e.RowIndex].Value.ToString(); 
    应该是:
    string id = this.GVlist.DataKeys[e.RowIndex]["DataKeyNames的值"].Value.ToString(); 
      

  6.   

    谢谢你们回答问题出在sql语句那里。。我是多表查询。。引起id名不明确。。还有致命的问题。。id没有查询。。所以报了这个错误
      

  7.   


    如果后台能得到值的话那么你看下
    前台删除按钮Command="delete"是否加了这个属性