tags:

views:

57

answers:

2

I just want to verify something. I believe it is likely that if I apply the using command to a SqlDataReader, that it will both close the data reader and dispose of it. For example:

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

Will that close the sdr SqlDataReader after it exits the Using code block. (I believe it will, but just want to verify.)

+3  A: 

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

Releases the resources used by the DbDataReader and calls Close.

Jeff Sternal
+3  A: 

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

SqlDataReader.Dispose Method

Releases the resources used by the DbDataReader and calls Close.

Heinzi