Application to SqlDataReader

I just want to check something. I believe that it is likely that if I applied the using command to SqlDataReader, then it would close the data reader and get rid of it. For example:

Using sdr As SqlDataReader = cm.ExecuteReader() Dim someInt As Integer = sdr.GetInt32(0) 'other details and actions End Using 

Will this close sdr SqlDataReader after exiting the Usage block. (I believe it will be, but just want to check.)

+6
using
source share
2 answers

Yes, the reader will be closed when it is removed. From the SqlDataReader.Dispose documentation :

Releases the resources used by DbDataReader and calls Close.

+5
source share

Yes. Using calls IDisposable.Dispose , and the MSDN page on SqlDataReader.Dispose says:

SqlDataReader.Dispose Method

Releases the resources used by DbDataReader and calls Close.

+5
source share

All Articles