当表格行列多时 就会用到分页查询列表的方法了
首先是调用 格式为
"select top (@limit) * from (select row_number() over(order by FId asc) as rownumber, * from T_Admin) temp_row where rownumber>(@offset-1) * @limit);";
切记 @limit必须加() 不加的会会直接报错
先创建ashx格式的文件 再写用程序为
public void GetUserList(HttpContext context)
{
int limit = Convert.ToInt32(context.Request["limit"]); // int格式先转换
int offset = Convert.ToInt32(context.Request["offset"]);
dynamic objJson = new ExpandoObject();
STKJ.BLL.T_Admin adminBLL = new STKJ.BLL.T_Admin();
int total = 0;
objJson.rows = adminBLL.GetUserList(limit,offset,out total);
objJson.total = total;
context.Response.Write(JsonConvert.SerializeObject(objJson));
}
然后再调用BLL的方法
public DataTable GetUserList(int limit, int offset,out int total)
{
return dal.GetUserList(limit, offset, out total);
}
最后再调用DAL方法
public DataTable GetUserList(int limit,int offset,out int total)
{
string sql = "select top (@limit) * from (select row_number() over(order by FId asc) as rownumber, * from T_Admin) temp_row where rownumber>(@offset-1) * @limit);";
string totalsql = "swlect COUNT(1) from T_Admin";
total = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.connStr, totalsql));
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@limit",SqlDbType.Int),
new SqlParameter("@offset",SqlDbType.Int)
};
para[0].Value = limit;
para[0].Value = offset;
return SqlHelper.ExecuteDataTable(SqlHelper.connStr, sql, para);
记得返回的数值
分页的话要加out
、