2017-09-17 53 views

回答

0

在删除功能中,您将创建一个数据表并从数据库中推送数据。但你没有exec删除数据库中的命令。所以它的工作,但不是从数据库中删除。

+0

你能帮忙吗? – Lalji

0
protected void JQGrid1_RowDeleting(object sender, Trirand.Web.UI.WebControls.JQGridRowDeleteEventArgs e) 
     {    
      DataTable dt = GetData(); 
      dt.PrimaryKey = new DataColumn[] { dt.Columns["CustomerID"] }; 
      DataRow rowToDelete = dt.Rows.Find(e.RowKey); 

      if (rowToDelete != null) 
{ 
       dt.Rows.Remove(rowToDelete); 
     // store your CustomerID in variable 
     string CustomerId = rowToDelete[0].ToString();//Datatype base on your sql table column 
     SqlConnection sqlConnection = new SqlConnection(); 
       sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["SQL2008_661086_trirandEntities"].ConnectionString; 
       sqlConnection.Open(); 

       string sqlStatement = "delete FROM Customers where CustomerID = "+ CustomerId +""; 

       SqlCommand cmd = new SqlCommand(sqlStatement , sqlConnection); 
     cmd.ExecuteNonQuery(); 


} 

      JQGrid1.DataSource = GetData(); 
      JQGrid1.DataBind(); 
} 

现在您的代码将按您的需要工作。