前一阵弄的一个分页,少量数据没问题.
public DataTable ShowPage(int PageIndex, int PageSize)
{
string strSql = ConfigurationManager.ConnectionStrings["PageTestConnectionString"].ToString();
SqlConnection con = new SqlConnection(strSql);
con.Open();
string sql = "select top " + PageSize + " * from NewsTest N where PID Not in (select top " + (PageIndex-1) * PageSize + " PID from NewsTest)";
SqlDataAdapter sdr = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
sdr.Fill(dt);
con.Close();
return dt;
}
public int ShowPageCount()
{
string strSql = ConfigurationManager.ConnectionStrings["PageTestConnectionString"].ToString();
SqlConnection con = new SqlConnection(strSql);
con.Open();
string sql = "select count(*) from NewsTest";
SqlCommand cmd = new SqlCommand(sql, con);
int i =Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
return i;
}
{
string strSql = ConfigurationManager.ConnectionStrings["PageTestConnectionString"].ToString();
SqlConnection con = new SqlConnection(strSql);
con.Open();
string sql = "select top " + PageSize + " * from NewsTest N where PID Not in (select top " + (PageIndex-1) * PageSize + " PID from NewsTest)";
SqlDataAdapter sdr = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
sdr.Fill(dt);
con.Close();
return dt;
}
public int ShowPageCount()
{
string strSql = ConfigurationManager.ConnectionStrings["PageTestConnectionString"].ToString();
SqlConnection con = new SqlConnection(strSql);
con.Open();
string sql = "select count(*) from NewsTest";
SqlCommand cmd = new SqlCommand(sql, con);
int i =Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
return i;
}