ASP.NET binding to DataReader

  • Thread starter Thread starter Andrew Robinson
  • Start date Start date
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
 
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...???
 
isn't that the purpose of an ODS? to link your data access layer to server
data controls?

-Andy
 
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...
 
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.





--------------------
 
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...
 
Steve,

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

-A
 
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.


--------------------
 
Back
Top