// Single edit/removal. Bulk(optional/later on) private void MenuItem_Click_1(object sender, RoutedEventArgs e) { STOCK s = (STOCK)sTOCKDataGrid.SelectedItem; using (Al_MujahidEntities context = new Al_MujahidEntities()) { var myObject = new STOCK { ID = s.ID }; context.STOCKs.Attach(myObject); context.STOCKs.Remove(myObject); context.SaveChanges(); Stock_Load(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { using (Al_MujahidEntities context = new Al_MujahidEntities()) { STOCK stock = new STOCK(); var decPrice = Convert.ToDecimal(this.pRICETextBox.Text); var intQTY = Convert.ToInt32(this.qTYTextBox.Text); stock.STOCK_ID = this.sTOCK_IDTextBox.Text; stock.NAME = this.nAMETextBox.Text; stock.PRICE = decPrice; stock.QTY = intQTY; context.STOCKs.Add(stock); context.SaveChanges(); Close(); } }