Ok, If I put a dbDataReader in a "Using" statement do I still need to explicitly call the dbDataReader.Close. In the .net documentation it says that "Using" a connection automatically Closes it. In the example below from MSDN it shows a dbDataReader without a "Using" and explicitly closing it:
Public Sub ReadData(ByVal connectionString As String)
Dim queryString As String = _
"SELECT OrderID, CustomerID FROM Orders"
Using connection As New OdbcConnection(connectionString)
Dim command As New OdbcCommand(queryString, connection)
connection.Open()
Dim reader As OdbcDataReader
reader = command.ExecuteReader()
' Always call Read before accessing data.
While reader.Read()
Console.WriteLine(reader.GetInt32(0) & ", " & reader.GetString(1))
End While
' Always call Close when done reading.
reader.Close()
End Using
End Sub
So isn't this cleaner and more efficient:
Public Sub ReadData(ByVal connectionString As String)
Dim queryString As String = _
"SELECT OrderID, CustomerID FROM Orders"
Using connection As New OdbcConnection(connectionString)
Using command As New OdbcCommand(queryString, connection)
connection.Open()
Using reader = command.ExecuteReader()
' Always call Read before accessing data.
While reader.Read()
Console.WriteLine(reader.GetInt32(0) & ", " & reader.GetString(1))
End While
End Using
End Using
End Using
End Sub
And then you wouldn't need to explicitly call the .Close on the Reader?
Thanks in advance