Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid & datasouce close

Reply
Thread Tools

DataGrid & datasouce close

 
 
PaulMac
Guest
Posts: n/a
 
      10-23-2003
Hello All,

I have a webpage containing a DataGrid control. The datasource is a
DataReader. The code is like so:

AsaCommand Cmd = new AsaCommand( "SELECT ... FROM ...", Db.Connection );
DataGridNet.DataSource = Cmd.ExecuteReader();
DataGridNet.DataBind();

Is it necessary to do an explicit close on the DataReader? In which case,
the code could be this:

AsaCommand Cmd = new AsaCommand( "SELECT ... FROM ...", Db.Connection );
AsaDataReader Reader = Cmd.ExecuteReader();
DataGridNet.DataSource = Reader;
DataGridNet.DataBind();
Reader.Close();

Thanks,
Paul


 
Reply With Quote
 
 
 
 
David
Guest
Posts: n/a
 
      10-23-2003
In article <#(E-Mail Removed)>, PaulMac wrote:
>
>
> Is it necessary to do an explicit close on the DataReader?


Yes, you should always close the DataReader explicitly. And you also
should close the connection, although you can specify this in the
ExecuteReader call.

>In which case,
> the code could be this:


>
> AsaCommand Cmd = new AsaCommand( "SELECT ... FROM ...", Db.Connection );
> AsaDataReader Reader = Cmd.ExecuteReader();
> DataGridNet.DataSource = Reader;
> DataGridNet.DataBind();
> Reader.Close();
>


Either,

ASADataReader = Cmd.ExecuteReader()
DataGridNet.DataSource = Reader;
DAtaGridNet.DataBind();
Reader.Close();
Db.Connection.Close();

or....
AsaDataReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridNet.DataSource = Reader;
DataGridNet.DataBind();
Reader.Close;


--
David
dfoster at
hotpop dot com
 
Reply With Quote
 
 
 
 
PaulMac
Guest
Posts: n/a
 
      10-23-2003
Thank you, David. I appreciate your help.

Paul

"David" <dfoster@127.0.0.1> wrote in message
news:(E-Mail Removed)...
> In article <#(E-Mail Removed)>, PaulMac wrote:
> >
> >
> > Is it necessary to do an explicit close on the DataReader?

>
> Yes, you should always close the DataReader explicitly. And you also
> should close the connection, although you can specify this in the
> ExecuteReader call.
>
> >In which case,
> > the code could be this:

>
> >
> > AsaCommand Cmd = new AsaCommand( "SELECT ... FROM ...", Db.Connection );
> > AsaDataReader Reader = Cmd.ExecuteReader();
> > DataGridNet.DataSource = Reader;
> > DataGridNet.DataBind();
> > Reader.Close();
> >

>
> Either,
>
> ASADataReader = Cmd.ExecuteReader()
> DataGridNet.DataSource = Reader;
> DAtaGridNet.DataBind();
> Reader.Close();
> Db.Connection.Close();
>
> or....
> AsaDataReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
> DataGridNet.DataSource = Reader;
> DataGridNet.DataBind();
> Reader.Close;
>
>
> --
> David
> dfoster at
> hotpop dot com



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
Multiple DataSouce for a DataGrid =?Utf-8?B?V2FyYW4=?= ASP .Net 1 05-09-2006 12:51 AM
need help on datasouce select guanfenglin@gmail.com ASP .Net 1 03-20-2006 02:51 AM
JavaMail POP3 folder.close() method close also store! Daniel Albisser Java 1 04-07-2004 03:45 PM
How to close child browser while parent close? Denon ASP .Net 1 11-14-2003 08:14 AM



Advertisments