Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataTable.GetChanges() Crashes...
Message
De
03/02/2007 18:37:18
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01189575
Message ID:
01192160
Vues:
21
I don't know Ben ... it works for me. The only difference I have is that I tested this out by adding the CommitProposedChanges() method to the DataSet class rather than to a DataTable class (I didn't want to refactor too much and I already had a DataSet class to test it out on).

Now, why that should make any difference, I have no idea. It seems to work ok though. Maybe you should try putting the method in the DataSet's class instead of the DataTable's?

Have you stuck in a breakpoint and actually looked at the data in a column that is supposed to have changed to see if it actually did? IOW, even if a DataColumn is still in the Proposed state, it should still show the new data in it if you look at row("MyColumn") in the debugger.

~~Bonnie


>Bonnie,
>
>Thanks for the help and making sure that my code is good. I do appreciate it. As to the other portion...
>
>Nowhere in my code do I use AcceptChanges(). I have no clue if it has to do with the DataGridView object on the form that the user interacts with though, I wouldn't think so, but I have been surprised on so many occasion by what .Net does that I would not discount it.
>
>Let me describe what I have, it might help you to see something that I am totally overlooking. I have a DataGridView, with it's DataSource set to the derived DataTable object in my DataSet. When the user changes a cell and loses focus from that cell, the data entered is immediatly pushed to the underlying DataTable automatically (I have not written any code that overrides the default behavior of the grid in this regard). On the form, when the user changes a selection in the ComboBox located above the grid, the SelectedIndexChanged() event then runs, and is supposed to repopulate the grid based on the selected filter in the combobox (This works prefectly). What I need to do though, is BEFORE I repopulate the grid with the new selection, I need to check if any changes have been made to the data in the grid (or in reality, the DataTable object) that have not yet been saved/pushed back to the SQL Server. If there ARE changes that have to be saved, then I query the user, asking if they
> want to save their changes or discard them.
>
>Now, that I fixed the GetChanges() method, I could use that to figure out if I have changes simple by looking at the resulting DataTable and its Row.Count property. If it is greater then 0 then there are changes. But It would be nice to figure out why I can't use HasChanges(). Although I can live without it for now, it might come in handy later.
>
>Based on your first response to my posting, I added the following event to the DataTable object:
>
>        Public Sub CommitProposedChanges()
>            '************************************************************************
>            ' Procedure/Function: CommitProposedChanges()
>            ' Author: Ben Santiago
>            ' Created On: 2/2/2007
>            ' Description:
>            '       Commits any "proposed" changes that have not yet ended.
>            '************************************************************************
>
>            For Each objDataRow As Data.DataRow In Me.Rows
>                If objDataRow.HasVersion(DataRowVersion.Proposed) Then
>                    objDataRow.EndEdit()
>                End If
>            Next
>        End Sub
>
>
>When I stepped through the code after making some changes to the data, I found that NONE of the rows presented themselves as in a "Proposed" state. Again, nowhere do I have AcceptChanges() or any other Commit-type code.
>
>>Ben,
>>
>>OK, that .Clone() override looks cool and it's a good way to handle the problem.
>>
>>Now, the other issue with the HasChanges() ... are you doing an .AcceptChanges() anywhere before you check for HasChanges()? That's the only thing that I can think of that would mark any changes back to their Original state.
>>
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform