DbHelperSQL.cs源文件中
加入以下代码
/// <summary>
/// 返回记录总数
/// </summary>
/// <param name="FieldName"></param>
/// <param name="TableName"></param>
/// <returns></returns>
public static int GetCount(string strWhere)
{
string strsql = strWhere;
object obj = DbHelperSQL.GetSingle(strsql);
if (obj == null)
{
return 1;
}
else
{
return int.Parse(obj.ToString());
}
}
/// 返回记录总数
/// </summary>
/// <param name="FieldName"></param>
/// <param name="TableName"></param>
/// <returns></returns>
public static int GetCount(string strWhere)
{
string strsql = strWhere;
object obj = DbHelperSQL.GetSingle(strsql);
if (obj == null)
{
return 1;
}
else
{
return int.Parse(obj.ToString());
}
}
DAL层中加入
public int GetCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" FROM users ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperSQL.GetCount(strSql.ToString());
//return DbHelperSQL.ExecuteSql(strSql.ToString());
}
BLL层中加入:{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" FROM users ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperSQL.GetCount(strSql.ToString());
//return DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 返回记录总数
/// </summary>
/// <param name="strWhere"></param>
/// <returns></returns>
public int GetCount(string strWhere)
{
return dal.GetCount(strWhere);
}
原来使用 dataset 进行读取记录数,当遇到海量数据时,会死掉,浪费掉所有内存,不可取
/// 返回记录总数
/// </summary>
/// <param name="strWhere"></param>
/// <returns></returns>
public int GetCount(string strWhere)
{
return dal.GetCount(strWhere);
}