private void btnAddProduct_Click(object sender, EventArgs e) { string pronameText = textBoxAddProName.Text; pronameText = pronameText.Trim(); if (pronameText != "") { panelProductAdd.Visible = false; btnEditProductClick.Enabled = true; btnDeleteProductClick.Enabled = true; //add product to the database //Get the data from the panel Product newProd = new Product(); newProd.ProdName = textBoxAddProName.Text; // writing new Product and ProductSupplier tables try { //Writing to Products Table int newProdID = ProductDB.AddProducts(newProd); products = ProductDB.GetProducts(); productDataGridView.DataSource = products; //Writing to ProductSupplier table //Supplier sup = suppliers[supplierNameComboBox.SelectedIndex]; //ProductsSuppliersDB.AddProductsSuppliers(newProdID, sup.SupplierID); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { MessageBox.Show("Fill up all the required data"); } textBoxAddProName.Text = ""; }