Best way to make a single "shared" dataset available to multiple Windows forms

J

John Granade

I'm looking for the best way to make a dataset available from multiple
Windows forms. The dataset is created from
an XML file. I have a main form (frmMain) that loads the dataset and reads
the data but then I have other forms that give the ability to add, modify,
and delete rows. This of course changes the dataset and I need that
reflected in the main form. At first I was actually passing a reference of
the dataset to the "modify" form (frmModify). That worked but I just didn't
like it and sometimes my dataview of the dataset in frmMain wouldn't catch
the updates and I'd have to rebind everything. It just seemed kludgy. Now
I'm going down the path of a shared dataset in a module but I can't decide
if it's better to use a module or a class or if this is even the right way
to go. I found a MS article that seems to hint that shared members in a
class are a better way to go than a module
(http://support.microsoft.com/default.aspx?scid=kb;en-us;311319) but I don't
really see why. I guess am looking to have an "application" level dataset
that I can bind to in multiple forms. Then when I make any changes to it,
any form with datagrids, dataviews, etc. automatically reflect those
changes.

Surely others have run in to the issue of accessing a single dataset from
multiple Windows Forms. What's the "best practices" way to expose and
update a dataset from multiple Windows forms?

Thanks,

John Granade
(e-mail address removed)
 
J

Joe Fallon

In a module I used this:
Public dsMain As New DataSet("MainDataSet")

It worked fine.

A VB module is a legacy holdover from VB6 and earlier.
There is no equivalent in C#.
Under the hood a module is converted to a shared class so I guess they are
suggesting you may as well learn how to write a shared class. It really does
not matter as far as execution goes.
 
C

Cor

Hi John,

I never did it this way.

But I think you can try it.

When you open the XML file in your designer you can make a dataset from
that.
It creates a XSD file and hidden, (you can see it when you set that in your
solution explorer as show all files) a dataset.vb class.

That is a complete class to read and write the dataset from everyplace.

I would give it a try in your situation.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top