分頁查詢詳情:sql
分頁查詢SQL語句spa
select top (@limit) * from (select row_number() over(order by FId desc) as rownumber,* from T_Products ) temp_row where rownumber>@offset code
@limit:條數blog
@offset :最小條數string
order by FId desc:數據根據FId倒序產品
T_Products:表格名稱it
分頁查詢一般配合計算sql計算總條數語句(select COUNT(1) from T_Products)使用class
實例:List
/// <summary> /// 前臺分頁查詢產品數據 /// </summary> /// <param name="limit">條數</param> /// <param name="offset">最小條數</param> /// <param name="total">返回總條數</param> /// <returns></returns> public DataTable GetQueryList(int limit, int offset, string Type, out int total){ //使用sql語句分頁查詢數據 string sql = "select top (@limit) * from (select row_number() over(order by FId desc) as rownumber,* from T_Products ) temp_row where rownumber>@offset "; //計算數據總條數 string totalsql = "select COUNT(1) from T_Products "; total = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.connStr, totalsql)); //使用鍵值對 對sql語句裏的佔位建進行替換 SqlParameter[] para = new SqlParameter[] { new SqlParameter("@limit",SqlDbType.Int), new SqlParameter("@offset",SqlDbType.Int), }; para[0].Value = limit; para[1].Value = offset; //返回一個Table return SqlHelper.ExecuteDataTable(SqlHelper.connStr, sql, para); }