admin 管理员组

文章数量: 887021


2023年12月17日发(作者:truncate在数据库中用来)

queryParamsType: "", queryParams: function (params) { return { pageSize: ze, //

每页记录条数 pageNumber: mber, //

当前页索引 }; }, columns: [{ field: 'Id', title: '编号', align: "center", halign: "center", valign: 'middle', sortable: true }, { field: 'Name', title: '姓名', align: "center", halign: "center", valign: 'middle' }, { field: 'Gender', title: '性别', align: "center", halign: "center", valign: 'middle' }, { field: 'Age', title: '年龄', align: "center", halign: "center", valign: 'middle' }, { field: 'operate', title: '操作', align: 'center', valign: 'middle', width: 200, events: { 'click #edit': function (e, value, row, index) { $('#id').val(); $('#name').val(); $('#gender').val(); $('#age').val(); }, 'click #delete': function (e, value, row, index) { deleteInfo(); } }, formatter: function (value, row, index) { var result = ""; result += ''; result += ''; return result; } }] }) //

修改信息 function editInfo() { $.ajax({ type: 'post', url: 'ashx/', dataType: 'json', data: { id: $('#id').val(), name: $('#name').val(), gender: $('#gender').val(), age: $('#age').val() }, success: function (data) { if (data == 'Yes') { $('#table').bootstrapTable('refresh'); $('#editModal').modal('hide'); } else {

else { alert('修改失败'); } } }) } //

删除信息 function deleteInfo(id) { $.ajax({ type: 'post', url: 'ashx/', dataType: 'json', data: { id: id }, success: function (data) { if (data == 'Yes') { $('#table').bootstrapTable('refresh'); } else { alert('删除失败'); } } }) } 后台查询代码using System;using c;using uration;using ;using ent;using ;using ;using ;using ;namespace { ///

/// TestHandler

的摘要说明 ///

public class QueryHandler : IHttpHandler { private static string ConnectionString = tionStrings["ConnectionString"].ToString(); public void ProcessRequest(HttpContext context) { tType = "text/plain"; //

获取分页参数 int pageSize = (t["pageSize"].ToString()); int pageNumber = (t["pageNumber"].ToString()); //

查询数据 int total = GetCount(); DataTable dataTable = GetDataTable(pageSize, pageNumber); //

格式化数据 var data = new { total = total, rows = dataTable }; (izeObject(data)); } public bool IsReusable { get

get { return false; } } //

数获取数量 private int GetCount() { string sql = "select count(*) from [TPerson]"; using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand(sql, connection); try { (); return 32(eScalar()); } catch { return -1; } } } //

分页查询 private DataTable GetDataTable(int pageSize, int pageNumber) { string sql = "select * from(select row_number() over(order by Id) as RowId, *from [TPerson]) as b where between (@pageNumber - 1) * @pageSize + 1 and @pageNumber * @pageSize order by Id"; using (SqlDataAdapter adapter = new SqlDataAdapter(ng(), ConnectionString)) { SqlParameter[] parameters = { new SqlParameter("@pageSize", pageSize), new SqlParameter("@pageNumber", pageNumber) };

DataTable dataTable = new DataTable(); ge(y()); (dataTable); return dataTable; } } }}后台编辑代码using System;using c;using uration;using ;using ent;using ;using ;using ;using ;namespace { ///

/// QueryHandler

的摘要说明 ///

public class EditHandler : IHttpHandler {

{ public void ProcessRequest(HttpContext context) { tType = "text/plain"; //

获取参数 int id = (t["id"].ToString()); string name = t["name"].ToString(); string gender = t["gender"].ToString(); int age = (t["age"].ToString()); //

查询参数 SqlParameter[] parameters = { new SqlParameter("@Id", id), new SqlParameter("@Name", name), new SqlParameter("@Gender", gender), new SqlParameter("@Age", age) }; //

修改信息 using (SqlConnection connection = new SqlConnection(tionStrings["ConnectionString"].ToString())) { SqlCommand command = new SqlCommand(); tion = connection; dText = "update [TPerson] set Name=@Name,Gender=@Gender,Age=@Age where Id=@Id"; ge(parameters); try { (); eNonQuery(); (izeObject("Yes")); } catch { (izeObject("No")); } } } public bool IsReusable { get { return false; } } }}后台删除代码


本文标签: 后台 代码 数据库 查询 获取