/// <summary> /// 增加一条数据 /// </summary> public int Add(LPWeb.Model.MarketingCategory model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MarketingCategory("); strSql.Append("CategoryName,GlobalId,Description)"); strSql.Append(" values ("); strSql.Append("@CategoryName,@GlobalId,@Description)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CategoryName", SqlDbType.NVarChar, 500), new SqlParameter("@GlobalId", SqlDbType.NVarChar, 255), new SqlParameter("@Description", SqlDbType.NVarChar, 500) }; parameters[0].Value = model.CategoryName; parameters[1].Value = model.GlobalId; parameters[2].Value = model.Description; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LPWeb.Model.MarketingCategory model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MarketingCategory set "); strSql.Append("CategoryName=@CategoryName,"); strSql.Append("GlobalId=@GlobalId,"); strSql.Append("Description=@Description"); strSql.Append(" where CategoryId=@CategoryId"); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.Int, 4), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 500), new SqlParameter("@GlobalId", SqlDbType.NVarChar, 255), new SqlParameter("@Description", SqlDbType.NVarChar, 500) }; parameters[0].Value = model.CategoryId; parameters[1].Value = model.CategoryName; parameters[2].Value = model.GlobalId; parameters[3].Value = model.Description; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LPWeb.Model.MarketingCategory GetModel(int CategoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CategoryId,CategoryName,GlobalId,Description from MarketingCategory "); strSql.Append(" where CategoryId=@CategoryId"); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.Int, 4) }; parameters[0].Value = CategoryId; LPWeb.Model.MarketingCategory model = new LPWeb.Model.MarketingCategory(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString()); } model.CategoryName = ds.Tables[0].Rows[0]["CategoryName"].ToString(); model.GlobalId = ds.Tables[0].Rows[0]["GlobalId"].ToString(); model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); return(model); } else { return(null); } }