public void Delete(DataGridView DGV) { using (var db = new NorthwindContext()) { string delId = DGV.SelectedRows[0].Cells[0].Value.ToString(); CustomerDemographics deleteRecord = db.CustomerDemographics.First(b => b.CustomerTypeID == delId); db.CustomerDemographics.Remove(deleteRecord); db.SaveChanges(); } }
private void button1_Click(object sender, EventArgs e) { using (NorthwindContext db = new NorthwindContext()) { if (String.IsNullOrEmpty(textBoxCustTypeID.Text)) { MessageBox.Show("Insert Customer type ID", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { CustomerDemographics cat = new CustomerDemographics(); cat.CustomerTypeID = textBoxCustTypeID.Text; cat.CustomerDesc = textBoxCustTypeDesc.Text; db.CustomerDemographics.Add(cat); db.SaveChanges(); this.Close(); } } }