jqGrid的ASP.net C#添加编辑删除数据库
问题描述:
我使用这个演示了jqGrid的ASP.net C#
没有更新http://www.trirand.net/examples/grid/editing_data/edit_add_delete/default.aspxjqGrid的ASP.net C#添加编辑删除数据库
数据更新和删除的jqGrid但不是在数据库中,我们怎样才能在数据库中还更新??
答
在删除功能中,您将创建一个数据表并从数据库中推送数据。但你没有exec删除数据库中的命令。所以它的工作,但不是从数据库中删除。
答
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();
}
现在您的代码将按您的需要工作。
你能帮忙吗? – Lalji