V
VB Programmer
I have a data class which returns a datareader. (Using an Access db.) I am
using this method to fill a dropdownlist. The problem is that after I've
ran it one time I get this error:
Could not use ''; file already in use.
I know that the datareader probably has it locked. Where should I close the
datareader?
Here's the function:
Public Function GetDataReader(ByVal strSql As String, ByVal strCnnString
As String) As OleDbDataReader
Dim cnn As New OleDbConnection(strCnnString)
cnn.Open()
Dim result As OleDbDataReader
Dim myCommand As New OleDbCommand
myCommand = New OleDbCommand(strSql, cnn)
result = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Return the datareader result
Return result
End Function
using this method to fill a dropdownlist. The problem is that after I've
ran it one time I get this error:
Could not use ''; file already in use.
I know that the datareader probably has it locked. Where should I close the
datareader?
Here's the function:
Public Function GetDataReader(ByVal strSql As String, ByVal strCnnString
As String) As OleDbDataReader
Dim cnn As New OleDbConnection(strCnnString)
cnn.Open()
Dim result As OleDbDataReader
Dim myCommand As New OleDbCommand
myCommand = New OleDbCommand(strSql, cnn)
result = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Return the datareader result
Return result
End Function