Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What kind of dataset is ds of changes?
Message
From
16/03/2010 16:02:25
 
 
To
16/03/2010 15:45:46
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454915
Message ID:
01454927
Views:
34
>>>Hi,
>>>
>>>When I get a dataset of changes from an existing dataset and then check for Tables property, I get NullReference error.
>>>
>>>Here is the simplified code:
>>>
>>>
>>>DataSet dsChanged = dsMyDataSet.GetChanges(DataRowState.Modified);
>>>foreach (DataTable Table in dsChanged.Tables)  //  !!!! Error Here!
>>>{
>>>
>>>}
>>>
>>>
>>>So what kind of dataset is the dataset of changes if it does not have tables? That is, how do you scan the values in this dataset?
>>
>>If no rows are found, it returns a null reference. From the MSDN article on it:
>>
>>
>>    // Check for changes with the HasChanges method first.
>>    if(!dataSet.HasChanges(DataRowState.Modified)) return;
>>
>>    // Create temporary DataSet variable and
>>    // GetChanges for modified rows only.
>>    DataSet tempDataSet = 
>>        dataSet.GetChanges(DataRowState.Modified);
>>
>>    // Check the DataSet for errors.
>>    if(tempDataSet.HasErrors)
>>    {
>>        // Insert code to resolve errors.
>>    }
>>
>>
>>Also, if you try to GetChanges after an AcceptChanges, it will return a null reference. Also, the .Added state takes preference to the .Modified state so keep that in mind too. There is a nice little example here (working with a datatable):
>>
>>http://blogs.msdn.com/spike/archive/2009/10/20/datatable-getchanges-datarowstate-modified-returns-null.aspx
>
>Here is what I found to be the issue (and it is not AcceptChanges). Before getting the dataset of changes the call to .EndEdit() for the row where changes were done should be called. Then the dataset of changes is populated. I still have an issue as the dataset of changes has All columns of the table - those that were changes and those that were not. And I thought that the dataset of changes will have a table with only changed columns.

I'm leary of that because I remember a bug where when a user control and calling .EndEdit() always caused HasChanges() to return true but the rowstate does stay as unchanged if no changes were made. Also, I recommend calling GetChanges on each table in the dataset and not on the dataset itself. It's been more reliable for me.
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform