Esempio n. 1
0
 public static List <T> ExecuteDataset <T>(string cmdText, params SqlParameter[] sqlParams)
 {
     if (string.IsNullOrEmpty(cmdText))
     {
         throw new ArgumentNullException("cmdText");
     }
     using (DataSet set = DataBase.ExecuteDataset(CommandType.Text, cmdText, sqlParams))
     {
         if ((set.Tables.Count < 1) || (set.Tables[0].Rows.Count < 1))
         {
             return(new List <T>(0));
         }
         return(DataBinding.LoadForList <T>(set.Tables[0].Rows));
     }
 }
Esempio n. 2
0
        public static List <T> Select <T>(string tableName, string fields, int topCount, string condition, string orderField, bool asc, params SqlParameter[] sqlParams)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentNullException("tableName");
            }
            if (condition == null)
            {
                condition = string.Empty;
            }
            condition = condition.Trim();
            if (!string.IsNullOrEmpty(condition) && !condition.StartsWith("WHERE", true, null))
            {
                condition = "WHERE " + condition;
            }
            if (string.IsNullOrEmpty(fields))
            {
                fields = "*";
            }
            string commandText = "SELECT";

            if (topCount > 0)
            {
                commandText = commandText + " TOP " + topCount.ToString();
            }
            string str2 = commandText;

            commandText = str2 + " " + fields + " FROM [" + tableName + "] " + condition;
            orderField  = orderField.Trim();
            if (!string.IsNullOrEmpty(orderField))
            {
                orderField  = " ORDER BY [" + orderField + "] " + (asc ? "ASC" : "DESC");
                commandText = commandText + orderField;
            }
            using (DataSet set = DataBase.ExecuteDataset(CommandType.Text, commandText, sqlParams))
            {
                if ((set.Tables.Count < 1) || (set.Tables[0].Rows.Count < 1))
                {
                    return(new List <T>(0));
                }
                return(DataBinding.LoadForList <T>(set.Tables[0].Rows));
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="fields"></param>
        /// <param name="condition"></param>
        /// <param name="fldName"></param>
        /// <param name="asc"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List <T> Select <T>(string tableName, string fields, string condition, string fldName, int asc, int pageIndex, int pageSize)
        {
            List <SqlParameter> list = new List <SqlParameter>(7);

            list.Add(new SqlParameter("@tblName", tableName));
            list.Add(new SqlParameter("@fldName", fldName));
            list.Add(new SqlParameter("@PageSize", pageSize));
            list.Add(new SqlParameter("@PageIndex", pageIndex));
            list.Add(new SqlParameter("@IsCount", SqlDbType.BigInt));
            list.Add(new SqlParameter("@OrderType", asc));
            list.Add(new SqlParameter("@strWhere", condition));
            using (DataSet set = DataBase.ExecuteDataset(CommandType.StoredProcedure, "GetRecordFromPage", list.ToArray()))
            {
                if ((set.Tables.Count < 1) || (set.Tables[0].Rows.Count < 1))
                {
                    return(new List <T>(0));
                }
                return(DataBinding.LoadForList <T>(set.Tables[0].Rows));
            }
        }
Esempio n. 4
0
        public static List <T> Select <T>(string tbname, string FieldKey, int PageCurrent, int PageSize, string FieldShow, string FieldOrder, string Where, int pageSize)
        {
            List <SqlParameter> list = new List <SqlParameter>(8);

            list.Add(new SqlParameter("@tbname", tbname));
            list.Add(new SqlParameter("@FieldKey", FieldKey));
            list.Add(new SqlParameter("@PageCurrent", PageCurrent));
            list.Add(new SqlParameter("@PageSize", PageSize));
            list.Add(new SqlParameter("@FieldShow", FieldShow));
            list.Add(new SqlParameter("@FieldOrder", FieldOrder));
            list.Add(new SqlParameter("@Where", Where));
            list.Add(new SqlParameter("@PageCount", 10));
            using (DataSet set = DataBase.ExecuteDataset(CommandType.StoredProcedure, "sp_pageView", list.ToArray()))
            {
                if ((set.Tables.Count < 1) || (set.Tables[0].Rows.Count < 1))
                {
                    return(new List <T>(0));
                }
                return(DataBinding.LoadForList <T>(set.Tables[0].Rows));
            }
        }