public class Handler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; StringBuilder tb = new StringBuilder(); DataBase db = new Database(); int pageSize = 10; int pageIndex = 0; 文字列タイプ = context.Request.Params["type"]; switch (type) { case "first": DataTable dt1 = db.GetDataSet("select Top 10 * from test", null).Tables[0]; tb.Append(Common.DataTableToJSON(dt1, true)); //DataTable转はJSON break; case "next": pageIndex = Convert.ToInt32(context.Request.Params["index"]); DataTable dt2 = db.GetDataSet("select top " pageSize.ToString() " * from test where id> (select max(id) from (select top " (pageSize * pageIndex).ToString() " id from test ) t)"、null).Tables[0]; tb.Append(Common.DataTableToJSON(dt2, true)); 休憩; case "pre": pageIndex = Convert.ToInt32(context.Request.Params["index"]); DataTable dt3 = db.GetDataSet("select top " pageSize.ToString() " * from test where id> (select max(id) from (select top " (pageSize * pageIndex).ToString() " id from test ) t)"、null).Tables[0]; tb.Append(JSONHelper.DataTableToJSON(dt)); 休憩; } context.Response.Write(tb.ToString()); } public bool IsReusable { get { return false; } } }
public class Handler : IHttpHandler { public void ProcessRequest(HttpContext context) { context .Response.ContentType = "テキスト/プレーン"; DataBase db = new Database(); int pageSize = 10; int pageIndex = 0; int.TryParse(context.Request.Params["index"], out pageIndex); 文字列タイプ = context.Request.Params["type"]; string sql = string.Format("select * from ( select row_number() over (order by id) as rowNum,* from test) as t " " where rowNum>{0} and rowNum<={ 1}", pageIndex * pageSize, (pageIndex 1) * pageSize); DataTable dt = db.GetDataSet(sql, null).Tables[0]; context.Response.Write(JSONHelper.DataTableToJSON(dt)); } public bool IsReusable { get { return false; } } }