private void RowEditingDone(object sender, DataGridRowEditEndingEventArgs e) { rowToChange = 0; if (e.EditAction == DataGridEditAction.Commit) //wykonywane gdy ktoś zatwierdzi enterem { if (MessageBox.Show("Czy chcesz zapisać zmiany?", "Na pewno?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { GridDataContext rowItem = (GridDataContext)e.Row.Item; //dostajemy wiersz w którym ktoś edytował rowToChange = rowItem.CustomerID; //jest ustawiane gdy ktoś wciśnie enter } } }
private int UpdateItem(GridDataContext rowItem) { CheckAndEstablishConnection(); var command = connection.CreateCommand(); command.CommandText = "UPDATE SalesLT.Customer SET FirstName=?, LastName=?, Title=? WHERE CustomerID=?"; command.Parameters.AddWithValue("@FirstName", rowItem.FirstName); command.Parameters.AddWithValue("@LastName", rowItem.LastName); command.Parameters.AddWithValue("@Title", rowItem.Title); command.Parameters.AddWithValue("@CustomerID", rowItem.CustomerID); var result = command.ExecuteNonQuery(); return(result); }