public static int SetRangeSql(ref SelectSqlSection sql, QueryTable table, QueryColumn IkeyColumn, int startPage, int pageSize, string orderByField) { string[] origanalStr = sql.ColumnNames; sql.ColumnNames = new string[] { "COUNT(*)" }; int count = Convert.ToInt32(sql.ToScalar()); if (!string.IsNullOrEmpty(orderByField)) { string[] orderStr = orderByField.Split(new char[] { '*' }); try { QueryColumn qc = TableMapModel.GetTableColumnByProName(orderStr[0], table); if (orderStr[1].Contains("Asc")) //升序 { sql.OrderBy(qc.Asc, IkeyColumn.Asc); } if (orderStr[1].Contains("Desc")) //降序 { sql.OrderBy(qc.Desc, IkeyColumn.Asc); } } catch (Exception e) { // throw e; } } int wPageSize = pageSize; if (pageSize * startPage > count) { wPageSize = count - pageSize * (startPage - 1); } if (pageSize > 0 && startPage > 0 && wPageSize > 0) { sql.SetSelectRange(wPageSize, pageSize * (startPage - 1), IkeyColumn); } sql.ColumnNames = origanalStr; return(count); }