<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SqlPage.aspx.cs" Inherits="SqlPage" %>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;public partial class SqlPage : System.Web.UI.Page{ public int pageCount = 0; public static string connString = "server=192.168.1.91;database=ReportDB;uid=sa;pwd=123456"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { pageCount = GetTotalPage(); if (Request["pageIndex"] != null && Request["pageSize"] != null) { int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 1 : Convert.ToInt32(Request["pageSize"]); int pageIndex = Convert.ToInt32(Request["pageIndex"]) == 0 ? 1 : Convert.ToInt32(Request["pageIndex"]); Response.Write(GetOnePage(pageSize, pageIndex)); Response.End(); } } } public int GetTotalPage() { DBHelper.connString = connString; string sql = "select count(*) from News"; int rs = Convert.ToInt32(DBHelper.ExecuteScalar(sql)); return rs; } public string GetOnePage(int pageSize, int pageIndex) { DBHelper.connString = connString; string sql = string.Empty; sql = "SELECT TOP " + pageSize + " NewsID,Title,SmallClassName,Author,Updatetime FROM News WHERE NewsID NOT IN (SELECT TOP " + pageSize * (pageIndex - 1) + " NewsID FROM News ORDER BY NewsID DESC) ORDER BY NewsID DESC"; DataTable dt = DBHelper.QueryBySql(sql); return ConvertJson.ToJson(dt, "News"); } }