SQL取top的方式,主要方法如下:
代码
protected DataTable DataBind(int pageSize, int pageNo)//获取分页数据
{
string sqlStr = "select top " + pageSize + " * from TestTable where ID NOT IN (select top " + pageSize * (pageNo - 1) + " ID from TestTable)";
SqlConnection conn = new SqlConnection(_connectionString);
SqlDataAdapter dad = new SqlDataAdapter(sqlStr, conn);
DataTable dt = new DataTable();
dad.Fill(dt);
int c = dt.Rows.Count;
return dt;
}
{
string sqlStr = "select top " + pageSize + " * from TestTable where ID NOT IN (select top " + pageSize * (pageNo - 1) + " ID from TestTable)";
SqlConnection conn = new SqlConnection(_connectionString);
SqlDataAdapter dad = new SqlDataAdapter(sqlStr, conn);
DataTable dt = new DataTable();
dad.Fill(dt);
int c = dt.Rows.Count;
return dt;
}
完整代码:Download