/// <summary> /// 更新一条数据 /// </summary> public void Update(ROYcms.Blog.Model.ROYcms_blog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ROYcms_blog set "); strSql.Append("user_id=@user_id,"); strSql.Append("tag=@tag,"); strSql.Append("Title=@Title,"); strSql.Append("Keyword=@Keyword,"); strSql.Append("Description=@Description,"); strSql.Append("content=@content,"); strSql.Append("Time=@Time"); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@tag", SqlDbType.NVarChar, 50), new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Keyword", SqlDbType.NVarChar, 1000), new SqlParameter("@Description", SqlDbType.NVarChar, 2000), new SqlParameter("@content", SqlDbType.Text), new SqlParameter("@Time", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.user_id; parameters[2].Value = model.tag; parameters[3].Value = model.Title; parameters[4].Value = model.Keyword; parameters[5].Value = model.Description; parameters[6].Value = model.content; parameters[7].Value = model.Time; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public ROYcms.Blog.Model.ROYcms_blog GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,user_id,tag,Title,Keyword,Description,content,Time from ROYcms_blog "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; ROYcms.Blog.Model.ROYcms_blog model = new ROYcms.Blog.Model.ROYcms_blog(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.tag = ds.Tables[0].Rows[0]["tag"].ToString(); model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.Keyword = ds.Tables[0].Rows[0]["Keyword"].ToString(); model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); model.content = ds.Tables[0].Rows[0]["content"].ToString(); if (ds.Tables[0].Rows[0]["Time"].ToString() != "") { model.Time = DateTime.Parse(ds.Tables[0].Rows[0]["Time"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ROYcms.Blog.Model.ROYcms_blog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ROYcms_blog("); strSql.Append("user_id,tag,Title,Keyword,Description,content,Time)"); strSql.Append(" values ("); strSql.Append("@user_id,@tag,@Title,@Keyword,@Description,@content,@Time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@tag", SqlDbType.NVarChar, 50), new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Keyword", SqlDbType.NVarChar, 1000), new SqlParameter("@Description", SqlDbType.NVarChar, 2000), new SqlParameter("@content", SqlDbType.Text), new SqlParameter("@Time", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.tag; parameters[2].Value = model.Title; parameters[3].Value = model.Keyword; parameters[4].Value = model.Description; parameters[5].Value = model.content; parameters[6].Value = model.Time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }