#region 选择全部新闻///<summary>/// 选择全部新闻///</summary>///<returns></returns>public DataTable SelectAll(int startIndex, int endIndex)
{
DataTable dt = new DataTable();
string sql = "with temptbl as( select ROW_NUMBER()over(order by id desc)as 行号,* from news) select * from temptbl where 行号 between @startIndex and @endIndex";
SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter ("@startIndex",startIndex),
new SqlParameter ("@endIndex",endIndex)
};
dt = new SQLHelper().ExecuteQuery(sql, paras, CommandType.Text);
return dt;
}
#endregion
查询记录总数:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace DAL
{
publicclass FenYeDAO
{
private SQLHelper sqlhelper;
publicFenYeDAO()
{
sqlhelper = new SQLHelper();
}
///<summary>/// 根据条件计算新闻记录数///</summary>///<param name="cond">条件,不用加where</param>///<returns></returns>publicintCalcCountNews(string cond)
{
string sql = "select count(*) from news";
if (!string.IsNullOrEmpty(cond))
{
sql += "where" + cond;
}
returnint.Parse(sqlhelper.ExecuteScalar(sql));
}
}
}