Exemplo n.º 1
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="pageCode">页码(从1开始)</param>
        /// <param name="pageSize">页行数</param>
        /// <param name="orderColumn">排序列</param>
        /// <param name="asc">true:升序;false:降序</param>
        /// <returns></returns>
        public DataTable ExecutePageDatatable(string commandText, int pageCode, int pageSize, string orderColumn, bool asc = true)
        {
            string SQLString = string.Format(@"
                SELECT  COUNT(1) FROM ( {0} ) ObjectData;

                SELECT  *
                FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY {1} {2} ) AS ID , *
                          FROM      ( {0} ) ObjectData
                        ) PageTemp
                WHERE   PageTemp.ID BETWEEN {3} AND {4};",
                                             commandText, orderColumn, asc ? " ASC " : " DESC ", (pageCode - 1) * pageSize + 1, pageCode * pageSize);

            try
            {
                DataSet ResultSet = MSSQLDBServer.ExecuteDataset(Connectstring, SQLString);

                int Total = int.Parse(ResultSet.Tables[0].Rows[0][0].ToString());

                DataTable ResultTable = ResultSet.Tables[1];
                ResultTable.ExtendedProperties.Add("Total", Total);

                return(ResultTable);
            }
            catch
            {
                string Error = string.Format("SQL:{0}", SQLString.Replace('\n', ' '));
                throw new Exception(Error);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 带Out或Output的查询表
 /// </summary>
 /// <param name="commandText"></param>
 /// <param name="outParameters"></param>
 /// <param name="commandParameters"></param>
 /// <param name="commandType"></param>
 /// <param name="transaction"></param>
 /// <returns></returns>
 public DataTable ExecuteDatatable(string commandText, out Dictionary <string, object> outParameters, IDataParameter[] commandParameters,
                                   CommandType commandType = CommandType.StoredProcedure, IDbTransaction transaction = null)
 {
     return(MSSQLDBServer.ExecuteDatatable(Connectstring, commandText, out outParameters, commandParameters, commandType, transaction));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 返回查询表
 /// </summary>
 /// <param name="commandText"></param>
 /// <param name="commandParameters"></param>
 /// <param name="commandType"></param>
 /// <param name="transaction"></param>
 /// <returns></returns>
 public DataTable ExecuteDatatable(string commandText, IDataParameter[] commandParameters = null, CommandType commandType = CommandType.Text,
                                   IDbTransaction transaction = null)
 {
     return(MSSQLDBServer.ExecuteDatatable(Connectstring, commandText, commandParameters, commandType, transaction));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 批量导入
 /// </summary>
 /// <param name="dataTable"></param>
 /// <param name="batchSize"></param>
 /// <param name="bulkCopyTimeout"></param>
 /// <param name="copyOptions"></param>
 /// <returns></returns>
 public bool ExecuteBulkCopy(DataTable dataTable, int batchSize = 10000, int bulkCopyTimeout = 60,
                             SqlBulkCopyOptions copyOptions     = SqlBulkCopyOptions.Default)
 {
     return(MSSQLDBServer.SQLBulkCopy(Connectstring, dataTable, batchSize, bulkCopyTimeout, copyOptions));
 }