/// <summary> /// 更新一条数据 /// </summary> public bool Update(BuysingooShop.Model.brand_attach model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_brand_attach set "); strSql.Append("brand_id=@brand_id,"); strSql.Append("theme_id=@theme_id,"); strSql.Append("size=@size,"); strSql.Append("img_url=@img_url,"); strSql.Append("remark=@remark"); strSql.Append("small_imgurl=@small_imgurl"); strSql.Append("add_time=@add_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@brand_id", SqlDbType.Int, 4), new SqlParameter("@theme_id", SqlDbType.Int, 4), new SqlParameter("@size", SqlDbType.NChar, 10), new SqlParameter("@img_url", SqlDbType.NChar, 100), new SqlParameter("@remark", SqlDbType.NVarChar, 100), new SqlParameter("@small_imgurl", SqlDbType.NChar, 100), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.brand_id; parameters[1].Value = model.theme_id; parameters[2].Value = model.size; parameters[3].Value = model.img_url; parameters[4].Value = model.remark; parameters[5].Value = model.small_imgurl; parameters[6].Value = model.add_time; parameters[7].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BuysingooShop.Model.brand_attach DataRowToModel(DataRow row) { BuysingooShop.Model.brand_attach model = new BuysingooShop.Model.brand_attach(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["brand_id"] != null && row["brand_id"].ToString() != "") { model.brand_id = int.Parse(row["brand_id"].ToString()); } if (row["theme_id"] != null && row["theme_id"].ToString() != "") { model.theme_id = int.Parse(row["theme_id"].ToString()); } if (row["size"] != null) { model.size = row["size"].ToString(); } if (row["img_url"] != null) { model.img_url = row["img_url"].ToString(); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["small_imgurl"] != null) { model.small_imgurl = row["small_imgurl"].ToString(); } if (row["add_time"] != null) { model.add_time = DateTime.Parse(row["add_time"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(BuysingooShop.Model.brand_attach model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_brand_attach("); strSql.Append("brand_id,theme_id,size,img_url,remark,small_imgurl,add_time)"); strSql.Append(" values ("); strSql.Append("@brand_id,@theme_id,@size,@img_url,@remark,@small_imgurl,add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@brand_id", SqlDbType.Int, 4), new SqlParameter("@theme_id", SqlDbType.Int, 4), new SqlParameter("@size", SqlDbType.NChar, 10), new SqlParameter("@img_url", SqlDbType.NChar, 100), new SqlParameter("@remark", SqlDbType.NVarChar, 100), new SqlParameter("@small_imgurl", SqlDbType.NChar, 100), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.brand_id; parameters[1].Value = model.theme_id; parameters[2].Value = model.size; parameters[3].Value = model.img_url; parameters[4].Value = model.remark; parameters[5].Value = model.small_imgurl; parameters[6].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BuysingooShop.Model.brand_attach GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,brand_id,theme_id,size,img_url,remark,small_imgurl,add_time from dt_brand_attach "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; BuysingooShop.Model.brand_attach model = new BuysingooShop.Model.brand_attach(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }