Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Entity.BASE_CONFIGURATION entity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Base_Configuration(");
            strSql.Append("ItemName,ItemValue,ItemDescription");
            strSql.Append(") values (");
            strSql.Append("@ItemName,@ItemValue,@ItemDescription");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ItemName",        SqlDbType.NVarChar,  50),
                new SqlParameter("@ItemValue",       SqlDbType.NVarChar, 500),
                new SqlParameter("@ItemDescription", SqlDbType.NVarChar, 500)
            };

            parameters[0].Value = entity.ItemName;
            parameters[1].Value = entity.ItemValue;
            parameters[2].Value = entity.ItemDescription;

            object obj = SqlServerHelper.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Entity.BASE_CONFIGURATION entity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Base_Configuration set ");

            strSql.Append(" ItemName = @ItemName , ");
            strSql.Append(" ItemValue = @ItemValue , ");
            strSql.Append(" ItemDescription = @ItemDescription  ");
            strSql.Append(" where ItemID=@ItemID ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@ItemID",          SqlDbType.Int,        4),
                new SqlParameter("@ItemName",        SqlDbType.NVarChar,  50),
                new SqlParameter("@ItemValue",       SqlDbType.NVarChar, 500),
                new SqlParameter("@ItemDescription", SqlDbType.NVarChar, 500)
            };

            parameters[3].Value = entity.ItemID;
            parameters[4].Value = entity.ItemName;
            parameters[5].Value = entity.ItemValue;
            parameters[6].Value = entity.ItemDescription;
            int rows = SqlServerHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Entity.BASE_CONFIGURATION GetEntity(int ItemID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ItemID, ItemName, ItemValue, ItemDescription  ");
            strSql.Append("  from Base_Configuration ");
            strSql.Append(" where ItemID=@ItemID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ItemID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ItemID;


            Entity.BASE_CONFIGURATION entity = new Entity.BASE_CONFIGURATION();
            DataSet ds = SqlServerHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ItemID"].ToString() != "")
                {
                    entity.ItemID = int.Parse(ds.Tables[0].Rows[0]["ItemID"].ToString());
                }
                entity.ItemName        = ds.Tables[0].Rows[0]["ItemName"].ToString();
                entity.ItemValue       = ds.Tables[0].Rows[0]["ItemValue"].ToString();
                entity.ItemDescription = ds.Tables[0].Rows[0]["ItemDescription"].ToString();

                return(entity);
            }
            else
            {
                return(null);
            }
        }