Dataset Copy method

  • Thread starter Thread starter Gary Shell
  • Start date Start date
G

Gary Shell

Still fighting with why the EndCurrentEdit seems to clear the underlying
Datasets.Item collection when a exception is thrown, I thought of a
workaround.

I thought I'd declare dsclone as Dataset, copy my actual dataset (which
should clone the structure and copy the data) and then after the exception
is thrown, restore the actual dataset from the clone. I used the following
to clone the dataset:
dsclone = Me.dsMetric.Copy

But what I got was NOT an exact copy. Here is the proof from the immediates
window immediately after executing the COPY method:

?dsmetric.Tables(0).Rows (0).ItemArray
{Length=9}
(0): 0 {Integer}
(1): "2451254"
(2): ""
(3): {System.DBNull}
(4): {System.DBNull}
(5): {System.DBNull}
(6): {System.DBNull}
(7): True {Boolean}
(8): False {Boolean}

?dsclone.Tables(0).Rows (0).ItemArray
{Length=9}
(0): 0 {Integer}
(1): ""
(2): ""
(3): ""
(4): {System.DBNull}
(5): ""
(6): {System.DBNull}
(7): True {Boolean}
(8): False {Boolean}

What is very odd, is after the EndCurrentEdit and the exception is thrown,
look at what happens to the actual dataset.

?dsmetric.Tables(0).Rows (0).ItemArray
{Length=9}
(0): 0 {Integer}
(1): ""
(2): ""
(3): ""
(4): {System.DBNull}
(5): ""
(6): {System.DBNull}
(7): True {Boolean}
(8): False {Boolean}

It's as if there are two instances of dsmetric, one that the immediate
window can see and one that the copy method and then latter the
EndCurrentEdit can see.

Can anybody shed ANY light on this. Browsing through the BindingContext
object it does look like MAYBE it might actually house an instance of the
dataset but I don't understand tat object well enough to understand if it
has any bearing on what I am seeing.

Thanks,

Gary
 
After playing with this a bit more it is obvious that the Copy method, can
only make a copy of the structure AND the data AFTER the EndCurrentEdit.
Prior to that a Copy method will only copy the STRUCTURE of the dataset
(including any default values). Which agrees with what I saw below. The
copied dataset is empty except for the defaulted fields (the two booleans)
and the strings that have a No Nulls constraint applied. So this is
beginning to make some sense.

But I am back to my original issue, when the EndCurrentEdit throws an
exception why does it wipe out the underlying dataset? And since that DOES
apparently happen, how do you prevent the user from loosing all the data
they keyed into the bound controls? I'd like for them to be able to just
fix the field that caused the exception and retry the EndCurrentEdit.

Arghhhhhhhhhhhhhhh!

Gary
 
Back
Top