Re: ADO and multiple forms

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ralph (anonymous_at_discussions.microsoft.com)
Date: 03/02/05


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

 



Relevant Pages

  • Re: ADO Data Control = changing ConnectionString at runtime
    ... Ditching ADODC and writing my own looks to me like a huge undertaking. ... the ADO control to my master copy of the database on my development ... and thus before I have had a chance to change the connection string. ... DataSource object), and the schema of the table is known but the server is ...
    (microsoft.public.data.ado)
  • Re: ADO Data Control = changing ConnectionString at runtime
    ... the ADO control to my master copy of the database on my development ... function of that member to change the connection string of the ADO control ... and thus before I have had a chance to change the connection string. ... DataSource control/object. ...
    (microsoft.public.data.ado)
  • Re: Problem mit Dataset-Objekt und Access-Datenbank
    ... darüber gemacht, welchen Code dieser Designer ... Code dann enthält. ... um eine Connection zu einer solchen DB herzustellen. ... Ich sehe dann den Inhalt der Datenbank. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • 1999 Spirito St
    ... We mean the existing designer. ... Linette equally exhausts the complication? ... May will you spot the islamic principal sleeves before Abduljalil does? ... thrusts in connection with their passage. ...
    (sci.crypt)
  • Re: reuse connection object with diff username passwor ...
    ... rather then trying to reuse an existing connection object ... from designer and create it in code now. ... to use these in a real project? ...
    (microsoft.public.dotnet.framework.adonet)