After several hours of line-by-line tracing, I have managed to figure out what the problem was. It appears to be an error in the documentation on datasets. This is the problem:
In the documentation (and I have checked it in several books and in Microsoft's help), in order to duplicate a dataset (and the contained tables), you are to use something like this:
Private Sub CopyDataSet(ByVal myDataSet As DataSet )
' Create an object variable for the copy.
Dim copyDataSet As DataSet
copyDataSet = myDataSet.Copy() <====
' Insert code to work with the copy.
End Sub
And of course, you are to use "clone()" to duplicate the structure but not the data, as below:
Private Sub GetClone(ByVal myDataSet As DataSet)
' Get a clone of the original DataSet.
Dim cloneSet As DataSet
cloneSet = myDataSet.Clone()
' Insert code to work with clone of the DataSet.
End Sub
Well, it turns out that for some reason, in Visual Studio 2003, the copy() is not correct. I was using it to duplicate a dataset into an object (which does all these calculations, etc) and then copying it back out to the parent form (from which it originally came). At the point where I used copy(), the dataset was not being properly copied. Instead, it acts more like clone() in that I get an empty dataset. The syntax that actually works for me looks more like this:
Private Sub CopyDataSet(ByVal myDataSet As DataSet )
' Create an object variable for the copy.
Dim copyDataSet As DataSet
copyDataSet = myDataSet
' Insert code to work with the copy.
End Sub
This copies both the dataset completely, as well as all of the tables within it (and their data), thus resolving the problem I was seeing. Basically, I was saving the tables properly (and doing the calcs), but then when the dataset was returned to the form, it was not properly being copied (thus the entries in my datagrid were being overwritten by duplicate "old" data)