コード例 #1
0
ファイル: SqlHelper.cs プロジェクト: wpmyj/CbznSystem
        public DataTable ToTable <T>(int page, int count, string where, string orderbycolumn, bool orderby)
        {
            /*SELECT * FROM ARTICLE w1
             * WHERE ID in
             * (
             * SELECT top 30 ID FROM
             * (
             *  SELECT top 45030 ID, YEAR FROM ARTICLE ORDER BY YEAR DESC, ID DESC
             * ) w ORDER BY w.YEAR ASC, w.ID ASC
             * )
             * ORDER BY w1.YEAR DESC, w1.ID DESC
             */
            StringBuilder sb = new StringBuilder(" select  ");

            sb.Append(DbComm.GetColumnStr <T>());
            sb.AppendFormat(" from {0} mi where ", typeof(T).Name);
            if (count > 0)
            {
                sb.AppendFormat(" {0} in ( select  top {1} {0} from ( select top {2} {0} from {3} where 1=1 {4} order by {0} desc ) mi1 order by mi1.{0} asc ) ", DbComm.GetPrimaryKey <T>(), count, (page * count) + count, typeof(T).Name, where);
            }
            else
            {
                sb.AppendFormat(" 1=1 {0} ", where);
            }
            if (string.IsNullOrEmpty(orderbycolumn))
            {
                orderbycolumn = DbComm.GetPrimaryKey <T>();
            }
            sb.AppendFormat(" order by mi.{0} ", orderbycolumn);
            sb.AppendFormat(" {0} ", @orderby ? "asc" : "desc");
            return(ToTable(sb.ToString()));
        }
コード例 #2
0
        public DataTable ToTable <T>(int page, int count, string where, string orderbycolumn, bool orderby)
        {
            StringBuilder sb = new StringBuilder(" select  ");

            sb.Append(DbComm.GetColumnStr <T>());
            sb.AppendFormat(" from {0} where 1=1 {1} ", typeof(T).Name, where);
            if (string.IsNullOrEmpty(orderbycolumn))
            {
                orderbycolumn = DbComm.GetPrimaryKey <T>();
            }
            sb.AppendFormat(" order by {0} ", orderbycolumn);
            sb.AppendFormat(" {0} ", @orderby ? "asc" : "desc");
            if (count > 0)
            {
                sb.AppendFormat(" limit {0},{1} ", page * count, count);
            }
            return(ToTable(sb.ToString()));
        }