private void button11_Click(object sender, EventArgs e) { // delete from the database and update the DVG try { if (CatIdTb.Text == "") { MessageBox.Show("Select the Category to delete"); } else { Con.Open(); string query = "delete from CategoryTbl where CatId=" + CatIdTb.Text + ""; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Category Deleted Successfully"); Con.Close(); populate(); CatNameTb.Text = ""; CatDescTb.Text = ""; CatIdTb.Text = ""; CatIdTb.Focus(); } }catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button10_Click(object sender, EventArgs e) { // Setting up the edit button try { if (CatIdTb.Text == "" || CatNameTb.Text == "" || CatDescTb.Text == "") { MessageBox.Show("Please select an item in the DataGrid"); } else { Con.Open(); string query = "update CategoryTbl set CatName='" + CatNameTb.Text + "',CatDesc='" + CatDescTb.Text + "' where CatId=" + CatIdTb.Text + ";"; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Category updated Successfully"); Con.Close(); populate(); CatNameTb.Text = ""; CatDescTb.Text = ""; CatIdTb.Text = ""; CatIdTb.Focus(); } }catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button9_Click(object sender, EventArgs e) { //Putting the information in the text boxes into the database with message boxes and error handling try { Con.Open(); string query = "insert into CategoryTbl values(" + CatIdTb.Text + ",'" + CatNameTb.Text + "','" + CatDescTb.Text + "')"; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Category Added Successfully"); Con.Close(); populate(); CatNameTb.Text = ""; CatDescTb.Text = ""; CatIdTb.Text = ""; CatIdTb.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }