Weird dataset.getchanges problem

  • Thread starter Thread starter John Sheppard
  • Start date Start date
J

John Sheppard

Hello there,

I have the following code; I do this as a work around for a
dataset.haschanges method which doesnt appear to work correctly either

For Each dt As DataTable In myDs.Tables
If Not dt.GetChanges(DataRowState.Added) Is Nothing Then hasChanges=true
If Not dt.GetChanges(DataRowState.Modified) Is Nothing Then
hasChanges=true
If Not dt.GetChanges(DataRowState.Deleted) Is Nothing Then
hasChanges=true
Next

On some (not all) of my datatables in the dataset, Visual Studio is claming
that certain columns do not exist when I hit the first dt.getchanges line.
The column that it claimes does not exist are not in the datatable
(according to the dataset visualiser)
I have tried regenerating my dataset.

Does anyone know what could be going on? :( I cant figure it out...
Thank you
John
 
John,

This sound strange

On some (not all) of my datatables in the dataset, Visual Studio is claming
that certain columns do not exist when I hit the first dt.getchanges line.
The column that it claimes does not exist are not in the datatable
(according to the dataset visualiser)

The GetChanges creates a real copy of your datatable, I have never seen
this, maybe it uses XML serializing behind the scene and then avoid
probably empty columns, can you check that? Would be interesting.

Cor
 
Thanks cor, I will check that out and report back. Sorry for the delay, it
was a long weekend here.
John
 
Hi Cor,

There are empty columns, but there are also empty columns in datatables that
work....that is, I cant see that they directly relate.

I don't know why, but if I do a merge into a clean dataset beforehand it
works.

It's threaded code and the original dataset comes from a baseform. These
things shouldnt really matter I dont think but maybe that has something to
do with it.For now I'm content to use the workaround below.

'This worked
Dim test As New dsBMS

test.Merge(myDs)
For Each dt As DataTable In test.Tables
If Not dt.GetChanges(DataRowState.Added) Is Nothing Then hasChanges=true
If Not dt.GetChanges(DataRowState.Modified) Is Nothing Then
hasChanges=true
If Not dt.GetChanges(DataRowState.Deleted) Is Nothing Then
hasChanges=true
Next

'This didnt work
For Each dt As DataTable In myDs.Tables
If Not dt.GetChanges(DataRowState.Added) Is Nothing Then hasChanges=true
If Not dt.GetChanges(DataRowState.Modified) Is Nothing Then
hasChanges=true
If Not dt.GetChanges(DataRowState.Deleted) Is Nothing Then
hasChanges=true
Next

Thanks Cor
John
 
Back
Top