/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.CMS_Config model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CMS_Config("); strSql.Append("Title,CopyRight,Mode)"); strSql.Append(" values ("); strSql.Append("@Title,@CopyRight,@Mode)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.VarChar, 50), new SqlParameter("@CopyRight", SqlDbType.VarChar, 50), new SqlParameter("@Mode", SqlDbType.VarChar, 50) }; parameters[0].Value = model.Title; parameters[1].Value = model.CopyRight; parameters[2].Value = model.Mode; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.CMS_Config model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CMS_Config set "); strSql.Append("Title=@Title,"); strSql.Append("CopyRight=@CopyRight,"); strSql.Append("Mode=@Mode"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.VarChar, 50), new SqlParameter("@CopyRight", SqlDbType.VarChar, 50), new SqlParameter("@Mode", SqlDbType.VarChar, 50), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.CopyRight; parameters[2].Value = model.Mode; parameters[3].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CMS_Config GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Title,CopyRight,Mode from CMS_Config "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Maticsoft.Model.CMS_Config model = new Maticsoft.Model.CMS_Config(); 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()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.CopyRight = ds.Tables[0].Rows[0]["CopyRight"].ToString(); model.Mode = ds.Tables[0].Rows[0]["Mode"].ToString(); return(model); } else { return(null); } }