Best way to share DataSets?

N

navilon

In my project I have several different forms that need access to the
same datasets, table adapters and binding sources. I have created a
static class called 'Globals.cs' which contains one of each. The
problem is that none of my forms recognize them. It's as if it will
only see instances within its own class.

Maybe I'm going about this the wrong way, it just seems redundant to
have every form have an instance of a dataset, table adapter and
binding source. Any information would be much appreciated.

Thanks,
Simon
 
N

Nicholas Paldino [.NET/C# MVP]

Simon,

First, create a base form which will expose the data
sets/tables/adapters which you added to the form through the designer. Make
sure the accessibility of those members is public or protected.

Then, in the constructor of that form, assign the local field references
to the ones that you expose in your static class. Make sure this is done
after InitializeComponent call.

Of course, there is going to be some overhead because the call to
InitializeComponent is going to create the instances of these fields. If
you are trying to eliminate that overhead (which shouldn't be much to begin
with), then this won't work, but the assumption is that you have some
configuration that you want to share.

Then, derive your forms from that base form.
 

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