在实现分页上 我是仅取出该取的数据 代码如下(其实代码可以写的灵活一点 给个参数 是否只取当前页的数据)- /// <summary>
- /// 某张表的数据读取
- /// </summary>
- /// <param name="strWhere">查询条件</param>
- /// <param name="start">数据导出开始点</param>
- /// <param name="limit">页面限制显示条数</param>
- /// <param name="strOrder">排序字段</param>
- /// <param name="current">是否只要当前页的数据</param>
- /// <returns></returns>
- public DataSet GetClientServiceRecords(string strWhere, int start, int limit, string strOrder, bool current)
- {
- var strSql = new StringBuilder();
- var sort = "";
- if (!string.IsNullOrEmpty(strOrder))
- {
- sort = "" + strOrder;
- }
- strSql.Append(" 这里是sql 语句");
- if (strWhere.Trim() != "")
- {
- strSql.Append(" WHERE " + strWhere + "\r\n");
- }
- strSql.Insert(0, "(\r\n");
- strSql.Append(")\r\n");
- strSql.Insert(0, "WITH TEMP AS");
- strSql.Append("SELECT * FROM TEMP\r\n");
- if (current)
- {
- strSql.Append(string.Format("WHERE ROW BETWEEN {0} AND {1}\r\n", start, limit));
- }
- strSql.Append("SELECT COUNT(1) FROM dbo.V_ClientServiceRecords\r\n");
- if (strWhere.Trim() != "")
- {
- strSql.Append("WHERE " + strWhere);
- }
- return SQLServerHelper.Query(strSql.ToString());
- }
复制代码 这个代码 不仅可以取出本页的数据 还可以取出数据的总数
|