写在*.aspx中
1 //增加行 OK 2 var addRow = function () { 3 var fieldName = "type"; //字段名 4 var modifyValue = "请输入"; //值 5 //var tempConfirm = confirm("modifyValue:" + modifyValue + " fieldName:" + fieldName)//确认 6 7 $.ajax({ 8 url: "Handler2.ashx", 9 datatype: "json", 10 data: { "RequestType": "inserted_Row", "modifyValue": modifyValue, "fieldName": fieldName }, 11 success: function (data) { 12 document.getElementById('spreadsheet').jexcel.refresh(); //刷新表格 13 } 14 }); 15 16 }View Code
写在*.ashx中
1 //前端增加行_写入数据库 OK 2 if (context.Request["RequestType"] == "inserted_Row") 3 { 4 string fieldName = context.Request["fieldName"].ToString(); //字段名 5 string modifyValue = context.Request["modifyValue"].ToString(); //值 6 7 8 //确认是否收到值 9 //Console.Write("来到Handler2中" + fieldName+ "_" + modifyValue); 10 //context.Response.Write("Handler2中取到的值:" + fieldName+ "_" + modifyValue); 11 12 string s0 = "insert into outstanding (" + fieldName + ") values ('" + modifyValue + "')"; 13 //context.Response.Write(s0); //确认值 14 15 //往数据库写入新信息 16 SqlConnection conn = new SqlConnection("server=150.17.232.180;database=SSC;uid=sscosd;pwd=BtQasYxonQuZqukIYkGM"); 17 conn.Open(); 18 SqlCommand cmd = new SqlCommand(s0, conn); //用来执行查询语句 19 cmd.ExecuteNonQuery(); //执行SQL语句,返回受影响的行数 20 cmd.Dispose(); //释放资源 21 conn.Close(); 22 23 };View Code
标签:同步,Handler2,数据库,jexcel,modifyValue,fieldName,context,var,conn From: https://www.cnblogs.com/automationanywhere/p/17479680.html