V
VB Programmer
I have a function that returns a datareader. The problem is that in the
function's FINALLY I close the datareader and set it to nothing. But,
BEFORE the Finally I "Return" the datareader (in the Try).
The problem is, by the time it's "returned" it says I already closed it.
Any ideas how I can overcome this?
Example:
Private Sub x
Dim dr as SqlDataReader
....
....
dr = GetDr(...) ' FAILS BECAUSE THE DATAREADER IS CLOSED BY NOW!
....
End Sub
Private Function GetDr(...) as SqlDataReader
Dim MyDataReader as SqlDataReader
Try
.....
....
Return MyDataReader
Catch
Finally
MyDataReader.Close
MyDataReader = Nothing
End Function
function's FINALLY I close the datareader and set it to nothing. But,
BEFORE the Finally I "Return" the datareader (in the Try).
The problem is, by the time it's "returned" it says I already closed it.
Any ideas how I can overcome this?
Example:
Private Sub x
Dim dr as SqlDataReader
....
....
dr = GetDr(...) ' FAILS BECAUSE THE DATAREADER IS CLOSED BY NOW!
....
End Sub
Private Function GetDr(...) as SqlDataReader
Dim MyDataReader as SqlDataReader
Try
.....
....
Return MyDataReader
Catch
Finally
MyDataReader.Close
MyDataReader = Nothing
End Function