Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What kind of dataset is ds of changes?
Message
 
 
To
16/03/2010 15:21:43
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454915
Message ID:
01454926
Views:
36
>>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.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform