Passing connection or dataset to a User Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could anyone provide a code example of passing an open oledbconnection or a
dataset to a User Control?
 
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
 
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?
 
Paul,

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

Kerry Moorman
 
Back
Top