private void button7_Click(object sender, EventArgs e) { // delete from the database and update the DVG try { if (ProdIdTb.Text == "") { MessageBox.Show("Select the Category to delete"); } else { Con.Open(); string query = "delete from ProductTbl where ProdId=" + ProdIdTb.Text + ""; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Category Deleted Successfully"); Con.Close(); populate(); ProdIdTb.Text = ""; ProdNameTb.Text = ""; ProdPriceTb.Text = ""; ProdQtyTb.Text = ""; ProdIdTb.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button6_Click(object sender, EventArgs e) { // Setting up the edit button try { if (ProdIdTb.Text == "" || ProdNameTb.Text == "" || ProdQtyTb.Text == "" || ProdPriceTb.Text == "") { MessageBox.Show("Please select an item in the DataGrid"); } else { Con.Open(); string query = "update ProductTbl set ProdName='" + ProdNameTb.Text + "',ProdQty='" + ProdQtyTb.Text + "', ProdPrice='" + ProdPriceTb + "', ProdCat='" + CatComboBox.SelectedValue.ToString() + "' where ProdId=" + ProdIdTb.Text + ";"; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Product updated Successfully"); Con.Close(); populate(); ProdIdTb.Text = ""; ProdNameTb.Text = ""; ProdPriceTb.Text = ""; ProdQtyTb.Text = ""; ProdIdTb.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button4_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 ProductTbl values(" + ProdIdTb.Text + ",'" + ProdNameTb.Text + "','" + ProdQtyTb.Text + "', '" + ProdPriceTb.Text + "', '" + CatComboBox.SelectedValue.ToString() + "')"; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Category Added Successfully"); Con.Close(); populate(); ProdIdTb.Text = ""; ProdNameTb.Text = ""; ProdPriceTb.Text = ""; ProdQtyTb.Text = ""; ProdIdTb.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }