Re: ADO and multiple forms
From: Ralph (anonymous_at_discussions.microsoft.com)
Date: 03/02/05
- Next message: William \(Bill\) Vaughn: "Re: ADO across vpn"
- Previous message: Macsicarr: "Re: A simple sort ... in principle!!"
- In reply to: Dale: "Re: ADO and multiple forms"
- Next in thread: Dale: "Re: ADO and multiple forms"
- Reply: Dale: "Re: ADO and multiple forms"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 2 Mar 2005 15:38:44 -0800
>-----Original Message-----
>I guess another question is what is the best way to
share the connection
>across forms? Like is declaring the connection and
recordsets public
>good practice.
>
>>
>> With code, I assume it's possible to have multiple
forms and only one
>> connection. That true?
>.
To answer you last question first - Yes.
The first rule when defining collaborations among objects
is to avoid passing values and pass objects.
When using the DE it is required that you to provide
a "DataSource" (Look up Data Aware Classes on the MSDN
CD) for your DataConsumer, in this case the DE designer.
MS provides an ADO Data Control (ADODBC) as an
expedientat which can be used for this purpose. As the
control is a "design-time" tool it works well when
designing and running simple "data aware" forms. However,
the ADODBC is a control and is constrainted by the
container (form) it is running under. (A simple analogy
is having a textbox be a global store for some string
value.)
The solution is to define your own DataSource in a "Data
Aware Class". You can create one simply by selecting the
Data Class wizard/template when you add a class to your
project. You can then use this class any place you need
to provide a "Data Source".
Now back to passing these things around.
You could create a global reference (the DE already is
one), but you are better off going the extra step and
create a 'constructor' for all forms/classes that might
have use of a connection.
Set someForm = New FormSome
someForm.Init( MyDataAwareClass )
If you do design your own DataSource Class be sure and
include the ADO Events and Error collection handling - so
you will get the same central data handling that DE has.
But that is just extra confusion at this point. <g>
Using Data Aware classes can dramatically streamline your
code and makes maintenance a lot easier compared to
passing connection strings or even connections around.
hth
-ralph
- Next message: William \(Bill\) Vaughn: "Re: ADO across vpn"
- Previous message: Macsicarr: "Re: A simple sort ... in principle!!"
- In reply to: Dale: "Re: ADO and multiple forms"
- Next in thread: Dale: "Re: ADO and multiple forms"
- Reply: Dale: "Re: ADO and multiple forms"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|