Matt Speller

Matt Speller

  • NA
  • 14
  • 0

Filtered Dataviews and adding rows to dataset....

Oct 11 2005 6:29 AM
Hi guys,

I have a Dataview that is a view of a datatable in a dataset, say view1 has the table property set to table1 from ds1.

view1 is bound to a listcontrol that shows a column on the screen for each row in the view1. view1 is filtered by some one screen objects, and on selection the rowFilter property on the view is set to limit the rows displayed.

Functionality also allows the user to add and delete rows from the underlying table1 from ds1. This ds1 is initially filled from a schema via an oracle reader. When the code adds or removes the rows from the dataset, the dataset.datatable.rows.remove(datarow) / add(datarow) syntax is used with success. The list shows the updates correctly.

BUT -

When I update multiple rows at once, seems to be four rows at the moment, I get a Null Data Exception in the system.data.dll. The call stack shows the following:- 

A first chance exception of type 'System.NullReferenceException' occurred in system.data.dll

Additional information: Object reference not set to an instance of an object.

  system.data.dll!System.Data.DataTable.RecordStateChanged(int record1 = -1, System.Data.DataViewRowState oldState1 = None, System.Data.DataViewRowState newState1 = None, int record2 = 1043, System.Data.DataViewRowState oldState2 = None, System.Data.DataViewRowState newState2 = Added) + 0x61 bytes 
  system.data.dll!System.Data.DataTable.SetNewRecord(System.Data.DataRow row = {Morpheus.RiskToolClient.Manacs.DataProcessing.PermissionItemsDS.PermissionItemsRow}, int proposedRecord = 1043, System.Data.DataRowAction action = Add, bool isInMerge = false) + 0x230 bytes 
  system.data.dll!System.Data.DataTable.InsertRow(System.Data.DataRow row = {Morpheus.RiskToolClient.Manacs.DataProcessing.PermissionItemsDS.PermissionItemsRow}, int proposedID = 1039, int pos = -1) + 0xc3 bytes 
  system.data.dll!System.Data.DataTable.AddRow(System.Data.DataRow row = {Morpheus.RiskToolClient.Manacs.DataProcessing.PermissionItemsDS.PermissionItemsRow}, int proposedID = -1) + 0x1b bytes 
  system.data.dll!System.Data.DataRowCollection.Add(System.Data.DataRow row = {Morpheus.RiskToolClient.Manacs.DataProcessing.PermissionItemsDS.PermissionItemsRow}) + 0x1e bytes 


This has to be something to do with the Dataview and the Rowfilter applied. If I set the view1.Table = null before I add these four rows, then reapply the dataview's table it works fine. (Although this causes numerous updates and flickering), also if I AcceptChanges after each row is added then again, it works just fine. I do not want to have to call AcceptChanges after each row I add, as I am not using a dataadapater I do not need to push these changes through to the database. The data is cached in the application and all changes are retrieved from the dataset before I update the database when the user closes the application.

So, has anyone come accross this type of issue surrounding Dataviews/Datasets/Rowfilters/AcceptChanges? Is there any property I can set, or method I have to override to stop this exception?

Regards

Matt

Answers (2)