Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

share dataset between 2 forms?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rain County - 07 Jan 2006 22:33 GMT
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
W.G. Ryan - 07 Jan 2006 23:01 GMT
> 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
[quoted text clipped - 9 lines]
> 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
Rain County - 08 Jan 2006 00:41 GMT
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...

>> 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
[quoted text clipped - 49 lines]
>
> Bill
W.G. Ryan - 08 Jan 2006 02:01 GMT
> Thank you Bill,
>
[quoted text clipped - 60 lines]
>>
>>Bill

Let me know how it goes, if you have any problems, just drop me a line
jonefer - 08 Jan 2006 20:00 GMT
Can I use this in VS2003?
Could you write an example in VB.NET?

Thanks

> > Thank you Bill,
> >
[quoted text clipped - 62 lines]
> >
> Let me know how it goes, if you have any problems, just drop me a line
Rain County - 27 Jan 2006 08:44 GMT
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

>> 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
[quoted text clipped - 49 lines]
>
> Bill

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.