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 15:21:43
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454915
Message ID:
01454916
Views:
50
>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
.·*´¨)
.·`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