Referencing other forms

  • Thread starter Thread starter Christopher Weaver
  • Start date Start date
C

Christopher Weaver

This is a broad question. I am developing a multiform Windows applications.
There is only one database involved. I would like to establish one
connection object and a few DataAdapters and DataSets that I can use in
several of the windows. How and where do I instantiate these objects so I
can utilize them from any of the forms in the application?

Thanks.
 
Christopher,

I would create a base form that instantiates this stuff for you, and
then derive from that form for all of your forms.

Also, you should not create one database connection (which might mean
you keep it open most of the time). If anything, have a factory method that
creates connections for you, which you then open and close as soon as you
are done.

Hope this helps.
 
He could store/return it in a set of static fields/properties/methods on
the base class, which would allow for that.
 
Christopher,
This is a broad question. I am developing a multiform Windows
applications. There is only one database involved. I would like to
establish one connection object and a few DataAdapters and DataSets that I
can use in several of the windows. How and where do I instantiate these
objects so I can utilize them from any of the forms in the application?

I would advise against this because you will almost certainly be holding
your connection open for as long as your app is open. This is OK when you're
the only user accessing your database, but not so good when there are more
than even a few concurrent users.

Instead, I would recommend a Data Access Layer, often known as a DAL.
This should get you started:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/daab.asp

Mark
 
Perhaps I'm expecting this to be altogether more visual in nature than it
is.

I thought that if I created form A and form B then put a bunch of code in
module C.cs that somehow I could get A and B to call the functions in C.cs
in such a manner that the code in C.cs could affect the properties of A and
B.

If I understand you correctly, I should start with frmSuperClass then
descend frmA and frmB from it so that I could put any code that I wanted to
affect frmA and frmB in frmSuperClass.

Regarding the connection. I open it when needed and close it when I'm
finished. It's just that I didn't want to use any additional resouces for
another connection object and I didn't want to add another layer of
complexity to the app. If I follow your reasoning, you would build a
function that would return a connection when called. Where would you put
such a function? Would this require that all forms that need to access data
be descended from a common form with the connection factory function within
it? What about the connection used by Crystal Reports?

Thanks.



Nicholas Paldino said:
Christopher,

I would create a base form that instantiates this stuff for you, and
then derive from that form for all of your forms.

Also, you should not create one database connection (which might mean
you keep it open most of the time). If anything, have a factory method
that creates connections for you, which you then open and close as soon as
you are done.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher Weaver said:
This is a broad question. I am developing a multiform Windows
applications. There is only one database involved. I would like to
establish one connection object and a few DataAdapters and DataSets that
I can use in several of the windows. How and where do I instantiate
these objects so I can utilize them from any of the forms in the
application?

Thanks.
 

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

Back
Top