protected void addCategoryButton_Click(object sender, EventArgs e) { Category category = new Category(); category.CategoryCode = categoryCodeTextBox.Text; category.CategoryName = categoryNameTextBox.Text; message.InnerHtml = categoryManager.Save(category); }
public string Save(Category category) { if(categoryGateway.Save(category)>0) { return "Added Successfully!"; } else { return "Could Not Added!"; } }
public int Save(Category category) { SqlConnection connection = new SqlConnection(databaseConString); string query = "INSERT INTO tbl_category VALUES ('" + category.CategoryCode + "','" + category.CategoryName + "')"; SqlCommand command = new SqlCommand(query,connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return rowAffected; }
public List<Category> GetAllCategoryByDropDownList() { SqlConnection connection = new SqlConnection(databaseConString); string query = "SELECT * FROM tbl_category"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List<Category> categoryList = new List<Category>(); while (reader.Read()) { Category category = new Category(); category.Id = int.Parse(reader["id"].ToString()); category.CategoryName = reader["category_name"].ToString(); categoryList.Add(category); } reader.Close(); connection.Close(); return categoryList; }