2017-09-17 87 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(); 
} 

現在您的代碼將按您的需要工作。

相關問題