Home All Groups Group Topic Archive Search About

share dataset between 2 forms?

Author
7 Jan 2006 10:33 PM
Rain County
I am using VS2005 standard edition. I have a database (MSACCESS) with a
Customer table.  On the main form (frmMain) of my windows application, I
have used the wizards to create a connection, a tableadapter, and a dataset.
frmMain has a datagridview for selecting a Customer (and then displaying
another gridview full of the customers orders).  A button click on frmMain
will bring up a second form, frmCustomer.  frmCustomer will be used to
delete or edit an existing customer or to add a new customer.

Now, the question:  How can I have frmCustomer access the same dataset
(dsCustomer) as frmMain?  How do I make the dataset be shared between forms?
Can I have a seperate class that contains and exposes the dataset?  If so,
how do I do it?  OR, is there a simple way to have the dataset be an object
of frmMain, but still be available as the datasource of frmCustomer?

Examples or links to examples would be appreciated.  I am sure this is
simple, but, apparently, so am I :)

TIA

Phil

Author
7 Jan 2006 11:01 PM
W.G. Ryan
Rain County wrote:
> I am using VS2005 standard edition. I have a database (MSACCESS) with a
> Customer table.  On the main form (frmMain) of my windows application, I
> have used the wizards to create a connection, a tableadapter, and a dataset.
> frmMain has a datagridview for selecting a Customer (and then displaying
> another gridview full of the customers orders).  A button click on frmMain
> will bring up a second form, frmCustomer.  frmCustomer will be used to
> delete or edit an existing customer or to add a new customer.
>
> Now, the question:  How can I have frmCustomer access the same dataset
> (dsCustomer) as frmMain?  How do I make the dataset be shared between forms?
> Can I have a seperate class that contains and exposes the dataset?  If so,
> how do I do it?  OR, is there a simple way to have the dataset be an object
> of frmMain, but still be available as the datasource of frmCustomer?
--All you need to do is create a class (or module in VB.nET) and have
the dataset as a Shared/Static property.  So it would work something
like this:

namespace CuckoozDemoNewsgroupStuff
{
     class DataHolder
     {

         private static dsCustomer _customerInstance;

         public static dsCustomer CustomerDataSet
         {
             get { return DataHolder._customerInstance; }
             set { DataHolder._customerInstance = value; }
         }
     }
}

Now, throughout your application, you can refer to this particular
dataset via DataHolder.CustomerDataSet.  So this is what you would fill
at the onset of the application and it's what you'd use, modfiy , update
etc throughout the application.  In VB.NET you'd do the same thing, you
just create the properties as Shared or stick them in a module (which
btw, is just a specialized class that has all Shared properties and
methods).
>
> Examples or links to examples would be appreciated.  I am sure this is
> simple, but, apparently, so am I :)
>
> TIA
>
> Phil
--Hopefully this gets you what you want but if you need any more help,
just let me know.

Cheers,

Bill
Show quote
>
>
Author
8 Jan 2006 12:41 AM
Rain County
Thank you Bill,

I'll give it a try as soon as I finish the weekend chores my wife has
assigned to me.

It looks like exactly what I want.

Thanks again for the reponse...

Show quote
"W.G. Ryan" <WilliamRyan@nospam.gmail.com> wrote in message
news:O3dH$49EGHA.3168@TK2MSFTNGP15.phx.gbl...
> Rain County wrote:
>> I am using VS2005 standard edition. I have a database (MSACCESS) with a
>> Customer table.  On the main form (frmMain) of my windows application, I
>> have used the wizards to create a connection, a tableadapter, and a
>> dataset.
>> frmMain has a datagridview for selecting a Customer (and then displaying
>> another gridview full of the customers orders).  A button click on
>> frmMain will bring up a second form, frmCustomer.  frmCustomer will be
>> used to delete or edit an existing customer or to add a new customer.
>>
>> Now, the question:  How can I have frmCustomer access the same dataset
>> (dsCustomer) as frmMain?  How do I make the dataset be shared between
>> forms? Can I have a seperate class that contains and exposes the dataset?
>> If so, how do I do it?  OR, is there a simple way to have the dataset be
>> an object of frmMain, but still be available as the datasource of
>> frmCustomer?
> --All you need to do is create a class (or module in VB.nET) and have the
> dataset as a Shared/Static property.  So it would work something like
> this:
>
> namespace CuckoozDemoNewsgroupStuff
> {
>     class DataHolder
>     {
>
>         private static dsCustomer _customerInstance;
>
>         public static dsCustomer CustomerDataSet
>         {
>             get { return DataHolder._customerInstance; }
>             set { DataHolder._customerInstance = value; }
>         }
>     }
> }
>
> Now, throughout your application, you can refer to this particular dataset
> via DataHolder.CustomerDataSet.  So this is what you would fill at the
> onset of the application and it's what you'd use, modfiy , update etc
> throughout the application.  In VB.NET you'd do the same thing, you just
> create the properties as Shared or stick them in a module (which btw, is
> just a specialized class that has all Shared properties and methods).
>>
>> Examples or links to examples would be appreciated.  I am sure this is
>> simple, but, apparently, so am I :)
>>
>> TIA
>>
>> Phil
> --Hopefully this gets you what you want but if you need any more help,
> just let me know.
>
> Cheers,
>
> Bill
>>
Author
8 Jan 2006 2:01 AM
W.G. Ryan
Rain County wrote:
Show quote
> Thank you Bill,
>
> I'll give it a try as soon as I finish the weekend chores my wife has
> assigned to me.
>
> It looks like exactly what I want.
>
> Thanks again for the reponse...
>
> "W.G. Ryan" <WilliamRyan@nospam.gmail.com> wrote in message
> news:O3dH$49EGHA.3168@TK2MSFTNGP15.phx.gbl...
>
>>Rain County wrote:
>>
>>>I am using VS2005 standard edition. I have a database (MSACCESS) with a
>>>Customer table.  On the main form (frmMain) of my windows application, I
>>>have used the wizards to create a connection, a tableadapter, and a
>>>dataset.
>>>frmMain has a datagridview for selecting a Customer (and then displaying
>>>another gridview full of the customers orders).  A button click on
>>>frmMain will bring up a second form, frmCustomer.  frmCustomer will be
>>>used to delete or edit an existing customer or to add a new customer.
>>>
>>>Now, the question:  How can I have frmCustomer access the same dataset
>>>(dsCustomer) as frmMain?  How do I make the dataset be shared between
>>>forms? Can I have a seperate class that contains and exposes the dataset?
>>>If so, how do I do it?  OR, is there a simple way to have the dataset be
>>>an object of frmMain, but still be available as the datasource of
>>>frmCustomer?
>>
>>--All you need to do is create a class (or module in VB.nET) and have the
>>dataset as a Shared/Static property.  So it would work something like
>>this:
>>
>>namespace CuckoozDemoNewsgroupStuff
>>{
>>    class DataHolder
>>    {
>>
>>        private static dsCustomer _customerInstance;
>>
>>        public static dsCustomer CustomerDataSet
>>        {
>>            get { return DataHolder._customerInstance; }
>>            set { DataHolder._customerInstance = value; }
>>        }
>>    }
>>}
>>
>>Now, throughout your application, you can refer to this particular dataset
>>via DataHolder.CustomerDataSet.  So this is what you would fill at the
>>onset of the application and it's what you'd use, modfiy , update etc
>>throughout the application.  In VB.NET you'd do the same thing, you just
>>create the properties as Shared or stick them in a module (which btw, is
>>just a specialized class that has all Shared properties and methods).
>>
>>>Examples or links to examples would be appreciated.  I am sure this is
>>>simple, but, apparently, so am I :)
>>>
>>>TIA
>>>
>>>Phil
>>
>>--Hopefully this gets you what you want but if you need any more help,
>>just let me know.
>>
>>Cheers,
>>
>>Bill
>>
>
Let me know how it goes, if you have any problems, just drop me a line
Author
8 Jan 2006 8:00 PM
jonefer
Can I use this in VS2003?
Could you write an example in VB.NET?

Thanks

Show quote
"W.G. Ryan" wrote:

> Rain County wrote:
> > Thank you Bill,
> >
> > I'll give it a try as soon as I finish the weekend chores my wife has
> > assigned to me.
> >
> > It looks like exactly what I want.
> >
> > Thanks again for the reponse...
> >
> > "W.G. Ryan" <WilliamRyan@nospam.gmail.com> wrote in message
> > news:O3dH$49EGHA.3168@TK2MSFTNGP15.phx.gbl...
> >
> >>Rain County wrote:
> >>
> >>>I am using VS2005 standard edition. I have a database (MSACCESS) with a
> >>>Customer table.  On the main form (frmMain) of my windows application, I
> >>>have used the wizards to create a connection, a tableadapter, and a
> >>>dataset.
> >>>frmMain has a datagridview for selecting a Customer (and then displaying
> >>>another gridview full of the customers orders).  A button click on
> >>>frmMain will bring up a second form, frmCustomer.  frmCustomer will be
> >>>used to delete or edit an existing customer or to add a new customer.
> >>>
> >>>Now, the question:  How can I have frmCustomer access the same dataset
> >>>(dsCustomer) as frmMain?  How do I make the dataset be shared between
> >>>forms? Can I have a seperate class that contains and exposes the dataset?
> >>>If so, how do I do it?  OR, is there a simple way to have the dataset be
> >>>an object of frmMain, but still be available as the datasource of
> >>>frmCustomer?
> >>
> >>--All you need to do is create a class (or module in VB.nET) and have the
> >>dataset as a Shared/Static property.  So it would work something like
> >>this:
> >>
> >>namespace CuckoozDemoNewsgroupStuff
> >>{
> >>    class DataHolder
> >>    {
> >>
> >>        private static dsCustomer _customerInstance;
> >>
> >>        public static dsCustomer CustomerDataSet
> >>        {
> >>            get { return DataHolder._customerInstance; }
> >>            set { DataHolder._customerInstance = value; }
> >>        }
> >>    }
> >>}
> >>
> >>Now, throughout your application, you can refer to this particular dataset
> >>via DataHolder.CustomerDataSet.  So this is what you would fill at the
> >>onset of the application and it's what you'd use, modfiy , update etc
> >>throughout the application.  In VB.NET you'd do the same thing, you just
> >>create the properties as Shared or stick them in a module (which btw, is
> >>just a specialized class that has all Shared properties and methods).
> >>
> >>>Examples or links to examples would be appreciated.  I am sure this is
> >>>simple, but, apparently, so am I :)
> >>>
> >>>TIA
> >>>
> >>>Phil
> >>
> >>--Hopefully this gets you what you want but if you need any more help,
> >>just let me know.
> >>
> >>Cheers,
> >>
> >>Bill
> >>
> >
> Let me know how it goes, if you have any problems, just drop me a line
>
Author
27 Jan 2006 8:44 AM
Rain County
Bill,

I appreciate the help you gave me previously. I have a new question that I
posted in the Windows.Forms group with no answer thus far.

Form a contains a dataGridView. In response to a menu item click, form A
creates and shows form B (from which I am giving the user the ability to
modify some display properties of the dgv, e.g. width, visible, column
heading, etc.). How can I access frmA.dgv from frmB? I thought that perhaps
declaring the dgv as Public would allow frmB to reference frmA.dgv, but it
doesn't.

I have learned to do it by passing a reference to the dgv when I call the
frmB constructor. However, I'm sure there must be a better and more general
way to share an object between forms. Is there?

Thanks, Phil

Show quote
"W.G. Ryan" <WilliamRyan@nospam.gmail.com> wrote in message
news:O3dH$49EGHA.3168@TK2MSFTNGP15.phx.gbl...
> Rain County wrote:
>> I am using VS2005 standard edition. I have a database (MSACCESS) with a
>> Customer table.  On the main form (frmMain) of my windows application, I
>> have used the wizards to create a connection, a tableadapter, and a
>> dataset.
>> frmMain has a datagridview for selecting a Customer (and then displaying
>> another gridview full of the customers orders).  A button click on
>> frmMain will bring up a second form, frmCustomer.  frmCustomer will be
>> used to delete or edit an existing customer or to add a new customer.
>>
>> Now, the question:  How can I have frmCustomer access the same dataset
>> (dsCustomer) as frmMain?  How do I make the dataset be shared between
>> forms? Can I have a seperate class that contains and exposes the dataset?
>> If so, how do I do it?  OR, is there a simple way to have the dataset be
>> an object of frmMain, but still be available as the datasource of
>> frmCustomer?
> --All you need to do is create a class (or module in VB.nET) and have the
> dataset as a Shared/Static property.  So it would work something like
> this:
>
> namespace CuckoozDemoNewsgroupStuff
> {
>     class DataHolder
>     {
>
>         private static dsCustomer _customerInstance;
>
>         public static dsCustomer CustomerDataSet
>         {
>             get { return DataHolder._customerInstance; }
>             set { DataHolder._customerInstance = value; }
>         }
>     }
> }
>
> Now, throughout your application, you can refer to this particular dataset
> via DataHolder.CustomerDataSet.  So this is what you would fill at the
> onset of the application and it's what you'd use, modfiy , update etc
> throughout the application.  In VB.NET you'd do the same thing, you just
> create the properties as Shared or stick them in a module (which btw, is
> just a specialized class that has all Shared properties and methods).
>>
>> Examples or links to examples would be appreciated.  I am sure this is
>> simple, but, apparently, so am I :)
>>
>> TIA
>>
>> Phil
> --Hopefully this gets you what you want but if you need any more help,
> just let me know.
>
> Cheers,
>
> Bill
>>

AddThis Social Bookmark Button