コード例 #1
0
        public List <KPICategoriesEntity> GetAllKPICategories()
        {
            string strSql = @"SELECT *
                              FROM [KPICategory]
                              ORDER BY ID DESC";
            List <KPICategoriesEntity> list = new List <KPICategoriesEntity>();
            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand dbCommand = db.GetSqlStringCommand(strSql))
            {
                try
                {
                    using (IDataReader dataReader = db.ExecuteReader(dbCommand))
                        while (dataReader.Read())
                        {
                            list.Add(KPICategoriesEntity.ReaderBind(dataReader));
                        }
                }
                catch (Exception ex)
                {
                    WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]"
                                                    , strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message));
                    return(null);
                }
            }
            return(list);
        }
コード例 #2
0
        /// <summary>
        /// Get an object entity
        /// </summary>
        public KPICategoriesEntity Get(int CategoryID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from [KPICategory] ");
            strSql.Append(" where ID=@ID ");
            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()))
            {
                try
                {
                    db.AddInParameter(dbCommand, "ID", DbType.Int32, CategoryID);
                    KPICategoriesEntity model = null;
                    using (IDataReader dataReader = db.ExecuteReader(dbCommand))
                    {
                        if (dataReader.Read())
                        {
                            model = KPICategoriesEntity.ReaderBind(dataReader);
                        }
                    }
                    return(model);
                }
                catch (Exception ex)
                {
                    WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]"
                                                    , strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message));
                    return(null);
                }
            }
        }