日期:2014-05-17 浏览次数:20501 次
public IList<Users> GetPageList(out int count,int ID,int pageindex = 1, int pagesize = 10)
{
IList<Users> list= new List<Users>();
int pagestart = (pageindex - 1)*pagesize;
string where = " where ID=@ID";
string sql="select * from (select row_number() over( order by ID desc) as rownum,ID,UserName from Users"+where+") as tb where tb.rownum > "+pagestart+" and tb.rownum <= "+pageindex*pagesize;
SqlParameter[] parameters = {
new SqlParameter("@ID", SqlDbType.Int,4)
};
parameters[0].Value = ID;
using (var dr = SqlHelper.ExecuteReader(connectionString, sql, parameters))
{
while (dr.Read())
{
list.Add(new Users(){
ID=int.Parse(dr["ID"].ToString()),
UserName=dr["UserName"].ToString()});
}
}
count=GetCount(where, parameters);
return list;
}
public int GetCount(string where ,SqlParameter[] parameters=null)
{
string sql = "select count(*) from Users " + where;
int rows = Convert.ToInt32(SqlHelper.ExecuteScalar(connectionString, sql, parameters));
return rows;
}