DataSet Access

  • Thread starter Thread starter Kent Barnes
  • Start date Start date
K

Kent Barnes

I have an application with multiple forms. I am trying to determine the
best way to share data between the various forms. I have experimented with
DataSets and have noticed that if use a dataset in one form (lets call it
form1) and update the data in form1 and then call form2 the data that is in
the form in form2 is the original data. The update does NOT appear to be
present?

kjbarnes(at)businessgoals(dot)com
 
Kent,

How are you sharing the DataSet across forms? It sounds like you have
multiple DataSets rather than multiple references to the same single
DataSet. If that's not the case, perhaps you're really updating the GUI and
not the underlying DataSet?
 
Kent:

I do this all of the time and have never had the problem you mention. The
first thing I'd wonder is how are you sure the changes aren't reflected?
Are you going by the GUI or have you set breakpoints and checked the
dataset? IF you filled a listbox for instance with a dataset during
Form_Load of your second form, then minimize it, make changes to the dataset
from Form1, whatever initialization code was in Form2 won't fire again just
by showing it so it may be that the dataset has actually reflected the
changes, it's just that the UI hasn't been refreshed so it doesn't appear
that way. I guess it depends on how you are loading and unloading your
forms. I can't tell from your post if Form2 is loaded already when you make
the update in form1 or not but it's somethign to look into.

Next, where are you storing the dataset so that all of the forms are
accessing it? Typically I'll create a singleton and have the dataset as a
property in that class. Then I reference can reference it from anywhere.

Verify that you are working with the same instance of the same dataset and
put a breakpoint in Form_Load (if you haven't loaded Form2 before making the
changes in Form1) or in Maximize...next, after you make your update in
form1, check the DataSet.Tables[IndexOrName].Rows.Count. When you hit your
breakpoint in Form2, verify the number. If it's a UI thing, the numbers
will agree although visually it may not look that way. If they don't agree,
then either you are referencing a different dataset or some other code is
making some changes.

HTH,

Bill
 
Back
Top