public static int GetCountByTableName(string tableName)
{
return shuju_Access.GetCount(string.Format("select Count(*) from {0} datatable", tableName));
}ide
public static int GetCount(string cmdText, params SqlParameter[] prams)
{
using (SqlConnection connection = new SqlConnection())
{
SqlCommand cmd = new SqlCommand();
CreateCommand(connection, cmd, cmdText, prams);
int num = 0;
object obj2 = cmd.ExecuteScalar();
if (obj2 == null)
{
num = 0;
}
else
{
num = Convert.ToInt32(obj2);
}
cmd.Parameters.Clear();
return num;
}
}orm
public static int GettTotalpage(string cmdtext, int pagesize)
{cmd
return GettTotalpage(cmdtext, pagesize, null);
}string
public static int GettTotalpage(string cmdtext, int pagesize, params SqlParameter[] prams)
{
int totalpages = 0;
int totalnums = 0;
totalnums = GetCount(cmdtext, prams);
if (totalnums <= 0)
{it
totalpages = 0;io
}
if (totalnums > 0)
{
float ss = totalnums / pagesize;
if (totalnums % pagesize == 0)
{
totalpages = int.Parse(System.Math.Ceiling(ss).ToString());
}
else
{
totalpages = int.Parse(System.Math.Ceiling(ss).ToString())+1;
}table
}class
return totalpages;
}object
=========一、是須要注意的是關於獲得總條數的時候須要用到的是:count(*)select
=========二、是計算頁數的是否,須要的是看什麼是否加1.