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 16:02:25
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454915
Message ID:
01454931
Views:
38
>>>>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.

Thank you for your recommendation. What I found, so far, working consistently is following (in pseudo code):
1. Call .HasVersion() on the row that user may or may not have changed (I only allow user to work on one row at a time)
2. If the 1. (above) is True, call .EndEdit() on the row that user made changes
3. At this point I thought I would get the DataSet of changes and send it to the BIZ/DAL for validation. But I changed my mind since the dataset of changes has all columns. So I might as well send to the BIZ/DAL the row on which user made changes.
4. Perform validation on the changed row and other nonsense before sending it to DAL/Stored procedure for update.


1.
"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