using System;
using System.Data;
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;
using System.Data.SqlClient;public partial class det_publish : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Server=(local);User Id=sa;Pwd=;DataBase=bookmanage");
        con.Open();
        SqlDataAdapter adapter = new SqlDataAdapter("select * from publishcompany", con);
        DataSet ds = new DataSet();
        adapter.Fill(ds, "publishcompany");
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "publishid" };
        GridView1.DataBind();
        con.Close();
       
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection con = new SqlConnection("Server=(local);User Id=sa;Pwd=;DataBase=bookmanage");
        con.Open();
        SqlCommand com = new SqlCommand("delete from publishcompany where publishid='" + GridView1.DataKeys[e.RowIndex].Value + "'", con);
        com.ExecuteNonQuery();
        con.Close();
        Page_Load(sender, e);
    }
}
删除数据删除不了,说我:您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
有谁告诉我哪里出错了呀.指导一下呀 

解决方案 »

  1.   

    状态为:deleted的ROW不可以去读它的VALUE
      

  2.   

      SqlCommand com = new SqlCommand("delete from publishcompany where publishid=" + GridView1.DataKeys[e.RowIndex].Value + "", con); 把单引号去掉试试,我以前遇到过
      

  3.   

    SqlCommand com = new SqlCommand("delete from publishcompany where publishid=" + GridView1.DataKeys[e.RowIndex].Value + "", con);  
      

  4.   

    Page_Load(sender, e); 去掉