Function behaves differently when passed a copy of the dataset

  • Thread starter Thread starter JerryK
  • Start date Start date
J

JerryK

Hi,

I have a strange problem I am trying to understand. I have a piece of code
that looks like:

Dim SourceDS as dataset
Dim ResultDS as dataset

SourceDS = RetrieveData()

ResultDS = ProcessData( SourceDS)

....

When I run this code I occasionally get the wrong information in the
ResultDS, the results Dataset. However, if I add a copy of the dataset,
everything works. That is, the code below returns the correct results.


Dim SourceDS as dataset
Dim ResultDS as dataset
Dim TempDS as dataset

SourceDS = RetrieveData()
TempDS = SourceDS.Copy

ResultDS = ProcessData( TempDS)

....

This is very strange and struggling to understand what is going on. BTW,
ProcessData() walks through the data in the dataset and may recursively call
itself passing a subset of the original data.

Any thoughts on what is going on?

Thanks,

Jerry
 
Is it possible that your function is changing the data? It is a reference
type so even if you pass it byVal, if your function modifies anything the
changes will be affect the original dataset...
 
Sorry, I was not being complete. The function does indeed change the
information in the dataset you pass, However, the function constructs a new
dataset based on the information it finds and returns that dataset. After
the function is complete, the original dataset is discarded.

So the question remains, why does passing a copy of the orginal dataset work
and using the original dataset does not work.

Sorry for the confusion,

jerry
 
Jerry:

Can you show me the function, it'd be a lot easier to debug then.

Thanks,

Bill
 
It is several 100 lines, so I hestitate to post it. The basic question is
how does a copy of a dataset differ from the original dataset? I tried
writing the dataset out to XML and comparing the copy vs. the original and
they were the same thing. Perhaps the problem lies in some fields that
WriteXML and WriteSchema do not serialize.
 
Back
Top