jexcel_删除行并同步数据库

发布时间 2023-06-14 11:14:31作者: AutomationAnywhere
写在*.aspx中
 1     //删除行 OK
 2     var myDeleteRow = function () {
 3         var DBID = document.getElementById("my_textbox").value;
 4         //var tempConfirm = confirm("DBID为:" + DBID); //弹出确认框 
 5         var tempConfirm = confirm("确定删除吗?"); //弹出确认框 
 6         if (tempConfirm == true) {
 7             $.ajax({
 8                 url: "Handler2.ashx", //删除行_写入数据库
 9                 datatype: "json",
10                 data: { "RequestType": "deleted_Row", "DBID": DBID },
11                 success: function (data) {
12                     document.getElementById('spreadsheet').jexcel.refresh(); //刷新表格
13                 },
14                 error: function (error) {
15                     alert(error.responseText);
16                 }
17             });
18         }
19     };
View Code

写在*.ashx中

 1 //前端删除行_写入数据库 OK 
 2         if (context.Request["RequestType"] == "deleted_Row") //save_data是homePage.aspx中自定义的请求类型
 3         {
 4             string dbId = context.Request["DBID"].ToString();            //ID                        
 5             string s0 = "delete from outstanding where id=" + dbId;
 6 
 7             //确认查询语句,是否正确
 8             //context.Response.Write(s0);
 9 
10             //往数据库写入新信息
11             SqlConnection conn = new SqlConnection("server=*.*.*.*;database=*;uid=*;pwd=*");
12             conn.Open();
13             //SqlCommand cmd = new SqlCommand(s0, class1.GetConnection1()); //用来执行查询语句
14             SqlCommand cmd = new SqlCommand(s0, conn);
15             //SqlCommand mycmd = new SqlCommand(strsql, myconn);            
16             cmd.ExecuteNonQuery();    //执行SQL语句,返回受影响的行数            
17             cmd.Dispose();            //释放资源
18             conn.Close();
19 
20         };
View Code