public void CreateNewsCategory(NewsCategory nc) { SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputNVarcharParameter("@name",100,nc.Name), SqlUtilities.GenerateInputNVarcharParameter("@remark",400,nc.Remark) }; string sql = "INSERT INTO news_categories (name, remark) VALUES (@name,@remark)"; SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param); }
public static void UpdateNewCategory(NewsCategory nc) { dal.UpdateNewsCategory(nc); }
public static void CreateNewsCategory(NewsCategory cat) { dal.CreateNewsCategory(cat); }
public void UpdateNewsCategory(NewsCategory nc) { SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputIntParameter("@id", nc.Id), SqlUtilities.GenerateInputNVarcharParameter("@name",100,nc.Name), SqlUtilities.GenerateInputNVarcharParameter("@remark",400,nc.Remark) }; string sql = "UPDATE news_categories SET name = @name , remark = @remark WHERE id = @id"; SqlHelper.ExecuteNonQuery(CommandType.Text, sql, param); }
public NewsCategory GetNewsCategoryById(int id) { NewsCategory nc = null; SqlParameter[] param = new SqlParameter[] { SqlUtilities.GenerateInputIntParameter("@id",id) }; string sql = "SELECT id, name, remark FROM news_categories WHERE id = @id"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, sql, param)) { while (dr.Read()) { nc = new NewsCategory(); nc.Id = dr.GetInt32(0); nc.Name = dr.GetString(1); nc.Remark = dr.GetString(2); } } return nc; }
public List<NewsCategory> GetNewsCategory() { string sql = "SELECT id, name, remark FROM news_categories"; List<NewsCategory> result = new List<NewsCategory>(); using(SqlDataReader dr=SqlHelper.ExecuteReader(CommandType.Text, sql, null)) { while(dr.Read()) { NewsCategory nc=new NewsCategory(); nc.Id=dr.GetInt32(0); nc.Name=dr.GetString(1); nc.Remark=dr.GetString(2); result.Add(nc); } } return result; }