Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

ASP.NET binding to DataReader

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Robinson - 24 Aug 2007 17:37 GMT
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
Mark Rae [MVP] - 24 Aug 2007 17:52 GMT
>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...???

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Andrew Robinson - 24 Aug 2007 17:56 GMT
isn't that the purpose of an ODS? to link your data access layer to server
data controls?

-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...???
Mark Rae [MVP] - 24 Aug 2007 21:23 GMT
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Steven Cheng[MSFT] - 27 Aug 2007 04:47 GMT
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.

--------------------
>From: "Mark Rae [MVP]" <mark@markNOSPAMrae.net>
>References: <Ot62W0m5HHA.5980@TK2MSFTNGP04.phx.gbl>
<OjMl28m5HHA.980@TK2MSFTNGP06.phx.gbl>
<eH8Eu#m5HHA.5844@TK2MSFTNGP02.phx.gbl>
>In-Reply-To: <eH8Eu#m5HHA.5844@TK2MSFTNGP02.phx.gbl>
>Subject: Re: ASP.NET binding to DataReader
[quoted text clipped - 14 lines]
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>NNTP-Posting-Host: 82-45-166-9.cable.ubr06.hari.blueyonder.co.uk
82.45.166.9
>Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP02.phx.gbl
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:39736
[quoted text clipped - 4 lines]
>
>If you have a DAL, the data controls are completely unnecessary...
Mark Rae [MVP] - 27 Aug 2007 09:36 GMT
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Steven Cheng[MSFT] - 27 Aug 2007 11:28 GMT
Thanks Mark,

yes...... it seems a tool issue, I'll take care and manually remove those
headers next time..... :)

Thanks for your care.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

--------------------
>From: "Mark Rae [MVP]" <mark@markNOSPAMrae.net>
>References: <Ot62W0m5HHA.5980@TK2MSFTNGP04.phx.gbl>
<OjMl28m5HHA.980@TK2MSFTNGP06.phx.gbl>
<eH8Eu#m5HHA.5844@TK2MSFTNGP02.phx.gbl>
<#O38ryo5HHA.1164@TK2MSFTNGP02.phx.gbl>
<OoifR0F6HHA.5608@TK2MSFTNGHUB02.phx.gbl>
>In-Reply-To: <OoifR0F6HHA.5608@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: ASP.NET binding to DataReader
[quoted text clipped - 14 lines]
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>NNTP-Posting-Host: 82-45-166-9.cable.ubr06.hari.blueyonder.co.uk
82.45.166.9
>Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP06.phx.gbl
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:39867
[quoted text clipped - 8 lines]
>Also, your replies appear to be including the full headers of the post
>you're replying to...
Andrew Robinson - 28 Aug 2007 04:39 GMT
Steve,

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

-A

> Thanks Mark,
>
[quoted text clipped - 51 lines]
>>Also, your replies appear to be including the full headers of the post
>>you're replying to...
Steven Cheng[MSFT] - 28 Aug 2007 05:08 GMT
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.

--------------------
>From: "Andrew Robinson" <nemoby@nospam.nospam>
>
[quoted text clipped - 59 lines]
>>>Also, your replies appear to be including the full headers of the post
>>>you're replying to...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.