473,564 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing other forms

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.
Nov 17 '05 #1
6 1083
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]
- mv*@spam.guard. caspershouse.co m

"Christophe r Weaver" <we*****@nospam verizon.net> wrote in message
news:O3******** ******@TK2MSFTN GP10.phx.gbl...
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.

Nov 17 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in news:uF******** ******@TK2MSFTN GP10.phx.gbl:
I would create a base form that instantiates this stuff for you,
and
then derive from that form for all of your forms.


I think he wants to share the instance data though, which this wont allow.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 17 '05 #3
He could store/return it in a set of static fields/properties/methods on
the base class, which would allow for that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Chad Z. Hower aka Kudzu" <cp**@hower.org > wrote in message
news:Xn******** *************** ***@127.0.0.1.. .
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in news:uF******** ******@TK2MSFTN GP10.phx.gbl:
I would create a base form that instantiates this stuff for you,
and
then derive from that form for all of your forms.


I think he wants to share the instance data though, which this wont allow.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/

Nov 17 '05 #4
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in news:On******** ******@TK2MSFTN GP09.phx.gbl:
He could store/return it in a set of static
fields/properties/methods on
the base class, which would allow for that.


Yes, but then he wont be able to bind at design time AFAIK.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 17 '05 #5
"Christophe r Weaver" <we*****@nospam verizon.net> wrote in message
news:O3******** ******@TK2MSFTN GP10.phx.gbl...

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/de.../html/daab.asp

Mark
Nov 17 '05 #6
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 [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uF******** ******@TK2MSFTN GP10.phx.gbl...
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]
- mv*@spam.guard. caspershouse.co m

"Christophe r Weaver" <we*****@nospam verizon.net> wrote in message
news:O3******** ******@TK2MSFTN GP10.phx.gbl...
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.


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2581
by: Tony Williams | last post by:
I have a form on which there is a tabcontrol and on this onr of the tabpages is a tick box which opens Outlook with data from the main form and prompts the user to amend the message before being sent. The code is Private Sub Loadtxt_Click() Dim oA As Outlook.Application Dim oM As Outlook.MailItem Set oA =...
2
4720
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value in the field of the last record entered on the subform. But what its doing is referencing whatever record the user clicked on last before closing...
6
2453
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if the amount of records for a particular date is positive, i want the form to stop running, if there are no records that contain the date in question,...
1
1658
by: jesse.hartwick | last post by:
Hey.. I was just wondering why there are so many ways to reference a form and what are the pros and cons of using each. I've seen at least 5 different ways, which is correct (or in what situations are each most correct)? Private Sub cmdButton_Click() ' This causes the same MsgBox to be displayed 10 times in A2K
4
1842
by: mplogue | last post by:
I have a form (frmMain) with a subform (frmSub), each with enumerated fields of the same name (txt1, txt2, etc). I'm trying to make a function that will take the values for each field in frmMain, and put them in the same-named field in the subform. Here's the function: '--------Start Code-------- Function cmdFillSub() Dim i As Integer
2
4052
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I want to do this as I want to use same subform on two different parent forms. Main problem is that the subform is not part of the forms collection. ...
0
1094
by: Chris | last post by:
I want to display a formview based on an objectdatasource. One of the things on the formview will be a link to a pdf. When I go into the edit template I would like a fileupload to display, which can be used to upload a new pdf. I would like my object to be as reusable as possible. Can anyone recommend a way of referencing the fileupload...
21
5079
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main form, the code errors out at the 2nd line. The error number is 13 and the description is "Type mismatch". Both controls are memo fields. I suspect...
5
1419
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
I am experiencing a lot of speed issues on initial app loads where we are referencing 3rd party 1.1 assemblies from 2.0 code. Those 1.1 assemblies reference things like System.Windows.Forms (totally unnecessarily I might add). I'm assuming our memory footprint will practically double by re-loading the System, System.Web,...
5
1371
kcdoell
by: kcdoell | last post by:
Good Morning: I am using the following code to add new records to a table that is on my Sub Form. Below is the code that I placed in my Before Update event on my Sub Form: Private Sub Form_BeforeUpdate(Cancel As Integer) 'When records are added it adds the coresponding LocationsID, YearID and Month IDs 'to the new record.
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.