Hi,
I've created an SQLConnection by dragging a DataAdapter onto the form. The
connection was named sqlConnection1.

When I try to reference this connection in code from another class, I cannot
find it. Intellisense only finds the classe SQLConnection. This must be a
scope issue.

How can I reference the forms connection object from code? Do I need to
create another connection in the class, or pass it to the class, or is there
a way of directly referencing it?

Many thanks for your advice in advance.
Ant

Re: Using a design time connection from a class by Cor

Cor
Wed Feb 01 00:35:01 CST 2006

Ant,

I assume that you use a version before 2004. Don't use a form to drag on,
use a component. Than that component is the class which you can instance in
all your forms.

I hope this helps,

Cor



Re: Using a design time connection from a class by Ant

Ant
Wed Feb 01 05:08:31 CST 2006

Hi Cor,

Thanks again. Yes I am using VS2003. What you mention sounds promising but
I'm not sure what you mean when you say,'don't use a form to drag on, use a
component'. Are you suggesting that you can drag onto a class? What is an
example of a 'component' that you talk about. i think this might solve the
problem.

Thanks kindly
Ant

"Cor Ligthert [MVP]" wrote:

> Ant,
>
> I assume that you use a version before 2004. Don't use a form to drag on,
> use a component. Than that component is the class which you can instance in
> all your forms.
>
> I hope this helps,
>
> Cor
>
>
>

Re: Using a design time connection from a class by Cor

Cor
Wed Feb 01 06:06:08 CST 2006

Ant,

Have a look at File->Add New Items and than choose component class, it is a
class on which you can drag as you said components (It has included more).

Cor

"Ant" <Ant@discussions.microsoft.com> schreef in bericht
news:BAC72706-FD1F-4625-96EB-C24082905702@microsoft.com...
> Hi Cor,
>
> Thanks again. Yes I am using VS2003. What you mention sounds promising but
> I'm not sure what you mean when you say,'don't use a form to drag on, use
> a
> component'. Are you suggesting that you can drag onto a class? What is an
> example of a 'component' that you talk about. i think this might solve the
> problem.
>
> Thanks kindly
> Ant
>
> "Cor Ligthert [MVP]" wrote:
>
>> Ant,
>>
>> I assume that you use a version before 2004. Don't use a form to drag on,
>> use a component. Than that component is the class which you can instance
>> in
>> all your forms.
>>
>> I hope this helps,
>>
>> Cor
>>
>>
>>



Re: Using a design time connection from a class by W

W
Wed Feb 01 08:05:23 CST 2006

Ant:

I'd just take the connectionstring that is generated from that connection
and create a new class or module with a static/shared property of type
SqlConnection. Set its connection string to the one that's generated in the
drag on connection (or better yet, store it in your app.config file) and
then you can reference it from anywhere in the application.
"Ant" <Ant@discussions.microsoft.com> wrote in message
news:5C29DF51-4A95-499B-AA73-AD9037E3B6E4@microsoft.com...
> Hi,
> I've created an SQLConnection by dragging a DataAdapter onto the form. The
> connection was named sqlConnection1.
>
> When I try to reference this connection in code from another class, I
> cannot
> find it. Intellisense only finds the classe SQLConnection. This must be a
> scope issue.
>
> How can I reference the forms connection object from code? Do I need to
> create another connection in the class, or pass it to the class, or is
> there
> a way of directly referencing it?
>
> Many thanks for your advice in advance.
> Ant
>



Re: Using a design time connection from a class by golden

golden
Wed Feb 15 23:15:41 CST 2006

my opinion about this from my understanding is dont drag the sql
connection rather than that in the class it self write the coding for
the connection by importing the sqlclient and write coding using the
sqlconnection object and sqlcommand object to write the command.Then
create the new object for the class in the form and then use the
connection.If you write in this way the class if be a reuable one and
can be used in the entire application.