Databinding technique

  • Thread starter Thread starter TheNortonZ
  • Start date Start date
T

TheNortonZ

I have several Winforms that have fields that are data bound to a dataset.
The dataset has about 12 different tables in it/

I have an assembly that does all of my math calculations on the data and I
pass the dataset by reference to the function calls into the assembly.

What I do right now is pass the dataset by reference and then within the
assembly, I copy the dataset data into matching objects and then I do the
calculations using the objects properties. Once I am done, I copy the
objects data back into the dataset and upon return from the function the new
data appears in the winform fields.

I feel that I have ventured down an incorrect road here.

My initial concern was that if I pass a dataset to a component by reference
and then 'some' of the data in the dataset does not calculate correctly,
that the dataset would be automatically updated and upon return from the
function call, I would end up have some good calculation data and some bad.
In other words, with being data bound to this dataset, changes in the
component would be immediately shown, good or bad.

In one way I feel that putting the datasets data into cooresponding objects
is a waste of processing power and space, but on the other hand it does give
me the capability to disconnect my dataset from the bound fields.

So I would ask, what is the correct way to do this? Have I gone down some
poorly designed code intensive path, or does it make sense to do it this
way?

Norton
 
TheNortonZ said:
I have several Winforms that have fields that are data bound to a dataset.
The dataset has about 12 different tables in it/

I have an assembly that does all of my math calculations on the data and I
pass the dataset by reference to the function calls into the assembly.

What I do right now is pass the dataset by reference and then within the
assembly, I copy the dataset data into matching objects and then I do the
calculations using the objects properties. Once I am done, I copy the
objects data back into the dataset and upon return from the function the
new data appears in the winform fields.

I feel that I have ventured down an incorrect road here.

My initial concern was that if I pass a dataset to a component by
reference and then 'some' of the data in the dataset does not calculate
correctly, that the dataset would be automatically updated and upon return
from the function call, I would end up have some good calculation data and
some bad. In other words, with being data bound to this dataset, changes
in the component would be immediately shown, good or bad.

In one way I feel that putting the datasets data into cooresponding
objects is a waste of processing power and space, but on the other hand it
does give me the capability to disconnect my dataset from the bound
fields.

So I would ask, what is the correct way to do this? Have I gone down some
poorly designed code intensive path, or does it make sense to do it this
way?

I'm afraid you suspicion is correct. A couple of things. First, don't
pass the DataSet by reference. It's a reference type so you are passing a
reference already. Passing by reference passes a reference to a reference.
That's not what you want. When you pass the DataSet by value and then
modify it in the method, the caller will see the changes.

Second, just modify the dataset. If you are unhappy with the changes you
have made, run DataSet.RejectChanges() before returning.

David
 
Well, lets see, whats the best word for my predicament....CRAP!

I have noticed, from the begining that by using the object layer there was
certainly a lot less typing. For example, to reference an item in the
dataset you can either do:

dataset.table.row(get the row number).item(itemname).

whereas with an object you have object.fieldname = ..

Or I guess you could shorten the dataset syntax by referencig the table at
the beginning with some sort of 'with'. I'm not sure.

Given project timelines and since I'm about a month away from completion, I
just guess I'll keep moving down the road I'm own and hope to come back and
rip out the guts of this thing and do it right.

The only positive thing is that this is a single use client side app where
the database will reside on the same machine (MSDE) so I don't believe I'll
have too much of a performance problem even with the extra layer.

Thanks for your suggestions though. I CAN change the ByRef to ByVal for the
dataset without too much of an effect.

Norton.
 
Back
Top