时间:2021-07-01 10:21:17 帮助过:2人阅读
调用示例:
call sp_hj_splitpage(1,3,‘*‘,‘hj_shangpin_cbj where 1=1‘,‘order by id desc‘);
C#调用示例:
#region 分页存储过程 /// <summary> /// 分页存储过程 /// </summary> /// <param name="table">表,可以关联:如 A left join B on A.id=B.Aid </param> /// <param name="fileds">字段值,获取全部字段用"*"</param> /// <param name="order">按什么字段排序</param> /// <param name="orderType">排序的方式 有ASC和DESC两种</param> /// <param name="pageIndex">页索引</param> /// <param name="pageSize">页大小</param> /// <param name="strWhere">查询条件,如不查可空 ""</param> /// <returns>返回一个DataTable</returns> public static DataTable GetSplitPageList(string table, string fileds, string order, string orderType, int pageSize, int pageIndex, string strWhere) { using (MySqlConnection conn = new MySqlConnection(connectionString)) { string strCmd = string.Format("call sp_hj_splitpage({0},{1},‘{2}‘,‘{3} where {4}‘,‘order by {5} {6}‘);", pageIndex, pageSize , fileds, table, strWhere, order, orderType); conn.Open(); MySqlCommand cmd = new MySqlCommand(strCmd, conn); DataTable dt = new DataTable(); MySqlDataReader dr = cmd.ExecuteReader(); dt.Load(dr); return dt; } } /// <summary> /// 获得分页总数 /// </summary> /// <param name="table"></param> /// <param name="strWhere"></param> /// <returns></returns> public static int GetSplitPageListCount(string table, string strWhere) { using (MySqlConnection conn = new MySqlConnection(connectionString)) { conn.Open(); string strSql = "select count(*) from " + table + " where " + strWhere; MySqlCommand cmd = new MySqlCommand(strSql, conn); return int.Parse(cmd.ExecuteScalar().ToString()); } } #endregion
原文网址:http://blog.csdn.net/jxncwzb/article/details/2883467
MYSQL- 分页存储过程
标签: