Example #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebApi_Model.T_IndexBackGround model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_IndexBackGround set ");
            strSql.Append("PhotoUrl=@PhotoUrl,");
            strSql.Append("Descriptions=@Descriptions");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PhotoUrl",     SqlDbType.NVarChar, 50),
                new SqlParameter("@Descriptions", SqlDbType.NVarChar, 50),
                new SqlParameter("@ID",           SqlDbType.Int, 4)
            };
            parameters[0].Value = model.PhotoUrl;
            parameters[1].Value = model.Descriptions;
            parameters[2].Value = model.ID;

            int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebApi_Model.T_IndexBackGround model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into T_IndexBackGround(");
            strSql.Append("PhotoUrl,Descriptions)");
            strSql.Append(" values (");
            strSql.Append("@PhotoUrl,@Descriptions)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PhotoUrl",     SqlDbType.NVarChar, 50),
                new SqlParameter("@Descriptions", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.PhotoUrl;
            parameters[1].Value = model.Descriptions;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebApi_Model.T_IndexBackGround DataRowToModel(DataRow row)
 {
     WebApi_Model.T_IndexBackGround model = new WebApi_Model.T_IndexBackGround();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["PhotoUrl"] != null)
         {
             model.PhotoUrl = row["PhotoUrl"].ToString();
         }
         if (row["Descriptions"] != null)
         {
             model.Descriptions = row["Descriptions"].ToString();
         }
     }
     return(model);
 }
Example #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebApi_Model.T_IndexBackGround GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,PhotoUrl,Descriptions from T_IndexBackGround ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            WebApi_Model.T_IndexBackGround model = new WebApi_Model.T_IndexBackGround();
            DataSet ds = DBHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }