Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Deleting a record
Message
De
02/10/2015 08:06:46
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Deleting a record
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01625376
Message ID:
01625376
Vues:
48
I have solved this by changing a setting on the oRND object: oRND.ImmediateDelete = true;

This allows the item to be actually deleted, rather than just tagging it for deletion and relying on the save to run afterwards.

Hi,

I have a XAML application done in MM.NET using C#. I am displaying a form with 2 business objects created like this:
    public partial class RunSheetsWindow : ABusinessWindow
    {
        private RunSheetHeader oRunSheetHeader;
        private RunSheetDetails oRunSheetDetails;
.
.
.
        public RunSheetsWindow()
        {
            this.RouteSearch = (Route)this.RegisterBizObj(new Route());
            this.Route = (Route)this.RegisterBizObj(new Route());

            this.oRunSheetHeader = (RunSheetHeader)this.RegisterPrimaryBizObj(new RunSheetHeader());
            this.oRunSheetDetails = (RunSheetDetails)this.RegisterBizObj(new RunSheetDetails());
            this.oRunSheetHeader.RegisterChildBizObj(this.oRunSheetDetails);
The form displays the Run Sheet Header and all the items that belong to the run sheet. The details are displayed in a grid and I want to let a user select an item in the grid and remove it (ie delete it from the underlying table).

This is the code I use to display/bind the data to the grid:
this.grdRunSheetDetails.DataContext = this.oRunSheetDetails.DataSet.Tables[this.oRunSheetDetails.TableName].DefaultView;
Here is the code I use to delete the items that are selected:
                    RunSheetDetails oRND = new RunSheetDetails();

                    foreach (DataRowView oRow in this.grdRunSheetDetails.SelectedItems)
                    {
                        oRND.GetRunSheetDetailsByPK((Guid)oRow.Row["rnd_pk"]);
                        oRND.Delete((Guid)oRow.Row["rnd_pk"]);
                        
                        mmSaveDataResult saveResult = oRND.SaveEntity();
                    }
This crashes with this error:

System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=SamaanSystems.IBC.Business
StackTrace:
at SamaanSystems.IBC.Business.RunSheetDetailsRules.CheckRulesHook[EntityType](mmBindingList`1 entityList) in D:\Development\VS2010\IBC\IBC Business Objects\RunSheetDetails\RunSheetDetailsRules.cs:line 41
at OakLeaf.MM.Main.Business.mmBusinessRule.CheckRules[EntityType](mmBindingList`1 entityList, mmRulesType rulesType)
at OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules(mmBusinessObjectGeneric`1 businessObject, mmBindingList`1 entityList, mmRulesType rulesType)
at OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules(mmBusinessObjectGeneric`1 businessObject, mmBindingList`1 entityList)
at OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.SaveEntity(EntityType entity)
at OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.SaveEntity()
at SamaanSystems.IBC.WPF.RunSheetsWindow.btnRemove_Click(Object sender, RoutedEventArgs e) in D:\Development\VS2010\IBC\IBC WPF\RunSheetsWindow.xaml.cs:line 225
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
InnerException:


This occurs in the last line of code below:
		public override bool CheckRulesHook<EntityType>(mmBindingList<EntityType> entityList)
		{
			// Call any generated rules
			if (entityList != null)
			{
				foreach (EntityType CurrentEntity in entityList)
				{
					this.CurrentEntity = CurrentEntity as mmBusinessEntity;
				
					if (this.CurrentEntity.GetDataRow().RowState == DataRowState.Added ||
					this.CurrentEntity.GetDataRow().RowState == DataRowState.Modified)
If I don't call the SaveEntity, the item does not get removed from the grid nor deleted from the table.

Any ideas how I am supposed to do this?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform