ASP.NET binding to DataReader

A

Andrew Robinson

I have a large collection of DAL code that returns lists of entities
(List<entity>) for general binding operations usually to a GridView via an
ObjectDataSource.

I think about binding directly to a SqlDataReader but how do I insure that
the Reader and its associated Connection both get closed? I would like to
continue using ObjectDataSources and am pretty sure I can pass a reader back
through this guy.

Thanks,

Andy
 
M

Mark Rae [MVP]

I have a large collection of DAL code I think about binding directly to a
SqlDataReader I would like to continue using ObjectDataSources

Slightly puzzled... You have a DAL *AND* you're using
ObjectDataSources...???
 
A

Andrew Robinson

isn't that the purpose of an ODS? to link your data access layer to server
data controls?

-Andy
 
M

Mark Rae [MVP]

isn't that the purpose of an ODS? to link your data access layer to server
data controls?

If you have a DAL, the data controls are completely unnecessary...
 
S

Steven Cheng[MSFT]

Hi Mark,

I think maybe Andrew also want to utilize the declarative/codeless
databinding model of ASP.NET 2.0 to populate the controls with records
retrieved through datareader.

Hi Anderw,

I also think that using an objectDataSource here is not quite confortable
and convenient. Because if you use DataReader, your business object query
the DB and return datareader, the close/disposing code should also be
performed by the buisness object. However, during the databinding period,
the objectdatasource will use the datareader to perform databinding against
the target databound control. Thus, your business class has to determine
when to close/dispose the datareader(this is the question here...). Or you
can let the ObjectDatasource to close the DataReader(expose from your
business object through some public interface/methods).

So far, I think you can consider use the following event of
objectdatasource control:

#ObjectDataSource.ObjectDisposing Event
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdat
asource.objectdisposing.aspx

it can let you do some work before the ObjectDataSource disposing the
underlying business class object. You can get the assocated DataReader from
the object instance and close it at that time. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.





--------------------
 
M

Mark Rae [MVP]

I think maybe Andrew also want to utilize the declarative/codeless
databinding model of ASP.NET 2.0 to populate the controls with records
retrieved through datareader.

Hmm, maybe... Seems like a totally unnecessary step to me...

Also, your replies appear to be including the full headers of the post
you're replying to...
 
A

Andrew Robinson

Steve,

Thanks for the info. I will look into the object disposing event on the ODS.

-A
 
S

Steven Cheng[MSFT]

No problem. If you have any further question, welcome to continue discuss
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top