Home All Groups Group Topic Archive Search About

Passing connection or dataset to a User Control

Author
17 Nov 2005 2:58 PM
Paul
Could anyone provide a code example of passing an open oledbconnection or a
dataset to a User Control?

Author
17 Nov 2005 3:33 PM
S.M. Altaf [MVP]
Paul,
Your question sounds a little too simple, so I'm going to assume there's
something I'm unaware of.

But to go by your question, create a property in your user control

Public Property CDataSource() As DataSet
Get
Return _ds
End Get
Set(ByVal Value As DataSet)
_ds = Value
End Set
End Property

And from your class,

MyControlName.CDataSource = ds

Of course, you'd have to add some mechanism to check, in the control,
whether a dataset has been assigned or not.

-Altaf

--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com

Show quote
"Paul" <P***@discussions.microsoft.com> wrote in message
news:02F8744F-D4D6-42C4-B6EB-2DB765F81686@microsoft.com...
> Could anyone provide a code example of passing an open oledbconnection or
> a
> dataset to a User Control?
Author
17 Nov 2005 7:29 PM
Paul
Thanks for this. I didn't really communicate my question well.

I have 6 user controls on my aspx page.

In each user control, I do ADO work.

Right now, I am opening and closing a database connection in each user
control.

I would rather not do this because I am concerned about opening and closing
connection so many times on one page. I am under the impression that opening
and closing db connections is "expensive" in terms of server resources. So I
am concerned that with heavy usage, the server would slow down response time
because of opening and closing db connections so frequesntly.

Is this a valid concern?

If so, then I thought one solution would be to open one connection per page,
then pass that connection to each user control by setting a property in the
<usercontrol:myusercontrol propertyname=dbconnection runat="server" /> tag.

Am I way off base here?





Show quote
"S.M. Altaf [MVP]" wrote:

>
> Paul,
> Your question sounds a little too simple, so I'm going to assume there's
> something I'm unaware of.
>
> But to go by your question, create a property in your user control
>
> Public Property CDataSource() As DataSet
> Get
> Return _ds
> End Get
> Set(ByVal Value As DataSet)
> _ds = Value
> End Set
> End Property
>
> And from your class,
>
> MyControlName.CDataSource = ds
>
> Of course, you'd have to add some mechanism to check, in the control,
> whether a dataset has been assigned or not.
>
> -Altaf
>
> --------------------------------------------------------------------------------
> All that glitters has a high refractive index.
> www.mendhak.com
>
> "Paul" <P***@discussions.microsoft.com> wrote in message
> news:02F8744F-D4D6-42C4-B6EB-2DB765F81686@microsoft.com...
> > Could anyone provide a code example of passing an open oledbconnection or
> > a
> > dataset to a User Control?
>
>
>
Author
17 Nov 2005 8:46 PM
Kerry Moorman
Paul,

Open and close the connection each time you need it. Connection pooling will
take care of the rest.

Kerry Moorman


Show quote
"Paul" wrote:

> Thanks for this. I didn't really communicate my question well.
>
> I have 6 user controls on my aspx page.
>
> In each user control, I do ADO work.
>
> Right now, I am opening and closing a database connection in each user
> control.
>
> I would rather not do this because I am concerned about opening and closing
> connection so many times on one page. I am under the impression that opening
> and closing db connections is "expensive" in terms of server resources. So I
> am concerned that with heavy usage, the server would slow down response time
> because of opening and closing db connections so frequesntly.
>
> Is this a valid concern?
>
> If so, then I thought one solution would be to open one connection per page,
> then pass that connection to each user control by setting a property in the
> <usercontrol:myusercontrol propertyname=dbconnection runat="server" /> tag.
>
> Am I way off base here?
>
>
>

>
> "S.M. Altaf [MVP]" wrote:
>
> >
> > Paul,
> > Your question sounds a little too simple, so I'm going to assume there's
> > something I'm unaware of.
> >
> > But to go by your question, create a property in your user control
> >
> > Public Property CDataSource() As DataSet
> > Get
> > Return _ds
> > End Get
> > Set(ByVal Value As DataSet)
> > _ds = Value
> > End Set
> > End Property
> >
> > And from your class,
> >
> > MyControlName.CDataSource = ds
> >
> > Of course, you'd have to add some mechanism to check, in the control,
> > whether a dataset has been assigned or not.
> >
> > -Altaf
> >
> > --------------------------------------------------------------------------------
> > All that glitters has a high refractive index.
> > www.mendhak.com
> >
> > "Paul" <P***@discussions.microsoft.com> wrote in message
> > news:02F8744F-D4D6-42C4-B6EB-2DB765F81686@microsoft.com...
> > > Could anyone provide a code example of passing an open oledbconnection or
> > > a
> > > dataset to a User Control?
> >
> >
> >

AddThis Social Bookmark Button