database access from multiple user controls

Junior Member

joined:Mar 30, 2005
posts: 84
votes: 0

I'm trying to move from <#INCLUDE> to user controls.

With an .aspx page, I just used <#INCLUDE> to set up database connections (connection string, OdbcConnection(), OdbcCommand, OdbcDataReader) once and accessed them from multiple <#INCLUDE> parts of the page. It was easy and it worked.

Now, using user controls instead, I seem to need to have to repeat this code in each and every user control. My best idea is to use an <#INCLUDE> in all those user controls.

Junior Member

joined:Mar 30, 2005
posts:84
votes: 0

Thanks,

Ocean, I think I see what you are doing that is different. I have been using the DataReader as a global object(?) that I could access form anywhere. You, instead, create a function that returns a DataSet. I hope that I'll be able to create a function that returns an OdbcDataReader that I can use While.read() on just the same.

Marcel, thanks for the link. Separating this into three layers is a bit beyond what I'm trying to accomplish here, and might be overkill. I just want to execute a SQL query and output the lines, nothing more. I'll still reread that article a few times to try to understand it all better.

Administrator

joined:Jan 14, 2004
posts:860
votes: 3

I do not normally use DataReaders directly. I use datasets since they allow me to cache the data to save future database hits when possible. Also makes managing database connections much much simpler. Since the connection is only opened long enough to read the data into the dataset, then closed.

Junior Member

joined:Mar 30, 2005
posts:84
votes: 0

I prefer to cache the data after I transform it to HTML (using Cache.Insert). Then when the same webpage is requested again, the HTML is already ready and stored in memory. Simplifying database connectivity certainly seems like a worthwhile goal, though.