private void picSaveADDPTD_Click(object sender, EventArgs e) { MyProdTypeCode myProdType = new MyProdTypeCode(); bool ok = true; errP.Clear(); try { myProdType.ProdTypeCode = txtProdTypeCode.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtProdTypeCode, MyEx.toString()); } try { myProdType.ProdTypeDesc = txtProdDesc2.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtProdDesc2, MyEx.toString()); } //Try Adding try { if (ok) { drProductType = dsBelfray.Tables["ProductType"].NewRow(); drProductType["productTypeCode"] = myProdType.ProdTypeCode; drProductType["productTypeDesc"] = myProdType.ProdTypeDesc; dsBelfray.Tables["ProductType"].Rows.Add(drProductType); daProductType.Update(dsBelfray, "ProductType"); MessageBox.Show("Product Type Added"); if (MessageBox.Show("Do you wish to add another product type?", "AddProductType", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { txtProdTypeCode.Text = ""; txtProdDesc2.Text = ""; formLoad = true; test = true; } else { pnlProdType.Enabled = false; txtProdTypeCode.Text = ""; txtProdDesc2.Text = ""; pnlDetails.Enabled = true; formLoad = true; test = true; } } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }
//THIS DOESNT WORK private void PicSaveADDPTD_Click(object sender, EventArgs e) { //ProductTypeCode drProductType = dsBelfray.Tables["ProductType"].Rows.Find(lblPTC.Text); MyProdTypeCode myProdType = new MyProdTypeCode(); bool ok = true; errP.Clear(); try { myProdType.ProdTypeCode = lblPTC.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblPTC, MyEx.toString()); } try { myProdType.ProdTypeDesc = txtProdDesc2.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtProdDesc2, MyEx.toString()); } //Try try { if (ok) { drProductType.BeginEdit(); drProductType["productTypeDesc"] = myProdType.ProdTypeDesc; drProductType.EndEdit(); daProductType.Update(dsBelfray, "ProductType"); pnlProdType.Enabled = false; lblPTC.Enabled = false; txtProdDesc2.Enabled = false; chkBxEditPTD.Checked = false; this.Update(); MessageBox.Show("Product Type Edited"); } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }