/// <summary> /// 更新一条数据 /// </summary> public bool Update(WeiXinPF.Model.wx_hb_category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_hb_category set "); strSql.Append("music=@music,"); strSql.Append("cName=@cName,"); strSql.Append("cTitle=@cTitle,"); strSql.Append("coverImg=@coverImg,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("cContent=@cContent,"); strSql.Append("createdate=@createdate"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@music", SqlDbType.VarChar, 800), new SqlParameter("@cName", SqlDbType.VarChar, 500), new SqlParameter("@cTitle", SqlDbType.VarChar, 300), new SqlParameter("@coverImg", SqlDbType.VarChar, 800), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@cContent", SqlDbType.VarChar, 2000), new SqlParameter("@createdate", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.music; parameters[1].Value = model.cName; parameters[2].Value = model.cTitle; parameters[3].Value = model.coverImg; parameters[4].Value = model.sort_id; parameters[5].Value = model.cContent; parameters[6].Value = model.createdate; parameters[7].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_hb_category DataRowToModel(DataRow row) { WeiXinPF.Model.wx_hb_category model = new WeiXinPF.Model.wx_hb_category(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["music"] != null) { model.music = row["music"].ToString(); } if (row["cName"] != null) { model.cName = row["cName"].ToString(); } if (row["cTitle"] != null) { model.cTitle = row["cTitle"].ToString(); } if (row["coverImg"] != null) { model.coverImg = row["coverImg"].ToString(); } if (row["sort_id"] != null && row["sort_id"].ToString() != "") { model.sort_id = int.Parse(row["sort_id"].ToString()); } if (row["cContent"] != null) { model.cContent = row["cContent"].ToString(); } if (row["createdate"] != null && row["createdate"].ToString() != "") { model.createdate = DateTime.Parse(row["createdate"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WeiXinPF.Model.wx_hb_category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_hb_category("); strSql.Append("music,cName,cTitle,coverImg,sort_id,cContent,createdate)"); strSql.Append(" values ("); strSql.Append("@music,@cName,@cTitle,@coverImg,@sort_id,@cContent,@createdate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@music", SqlDbType.VarChar, 800), new SqlParameter("@cName", SqlDbType.VarChar, 500), new SqlParameter("@cTitle", SqlDbType.VarChar, 300), new SqlParameter("@coverImg", SqlDbType.VarChar, 800), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@cContent", SqlDbType.VarChar, 2000), new SqlParameter("@createdate", SqlDbType.DateTime) }; parameters[0].Value = model.music; parameters[1].Value = model.cName; parameters[2].Value = model.cTitle; parameters[3].Value = model.coverImg; parameters[4].Value = model.sort_id; parameters[5].Value = model.cContent; parameters[6].Value = model.createdate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_hb_category GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,music,cName,cTitle,coverImg,sort_id,cContent,createdate from wx_hb_category "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; WeiXinPF.Model.wx_hb_category model = new WeiXinPF.Model.wx_hb_category(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }