/// <summary> /// 增加一条数据 /// </summary> public int Add(ROYcms.Blog.Model.ROYcms_Blog_user model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ROYcms_Blog_user("); strSql.Append("user_id,BlogTitle,Keyword,Description,Time)"); strSql.Append(" values ("); strSql.Append("@user_id,@BlogTitle,@Keyword,@Description,@Time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@BlogTitle", SqlDbType.NVarChar, 100), new SqlParameter("@Keyword", SqlDbType.NVarChar, 1000), new SqlParameter("@Description", SqlDbType.NVarChar, 2000), new SqlParameter("@Time", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.BlogTitle; parameters[2].Value = model.Keyword; parameters[3].Value = model.Description; parameters[4].Value = model.Time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 根据 user_id 更新 /// </summary> public void Update_user_id(ROYcms.Blog.Model.ROYcms_Blog_user model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ROYcms_Blog_user set "); strSql.Append("user_id=@user_id,"); strSql.Append("BlogTitle=@BlogTitle,"); strSql.Append("Keyword=@Keyword,"); strSql.Append("Description=@Description,"); strSql.Append("Time=@Time"); strSql.Append(" where user_id=@user_id "); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@BlogTitle", SqlDbType.NVarChar, 100), new SqlParameter("@Keyword", SqlDbType.NVarChar, 1000), new SqlParameter("@Description", SqlDbType.NVarChar, 2000), new SqlParameter("@Time", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.BlogTitle; parameters[2].Value = model.Keyword; parameters[3].Value = model.Description; parameters[4].Value = model.Time; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public ROYcms.Blog.Model.ROYcms_Blog_user GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,user_id,BlogTitle,Keyword,Description,Time from ROYcms_Blog_user "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; ROYcms.Blog.Model.ROYcms_Blog_user model = new ROYcms.Blog.Model.ROYcms_Blog_user(); 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.BlogTitle = ds.Tables[0].Rows[0]["BlogTitle"].ToString(); model.Keyword = ds.Tables[0].Rows[0]["Keyword"].ToString(); model.Description = ds.Tables[0].Rows[0]["Description"].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); } }