{"Invalid attempt to Read when reader is closed.

akhanmac

New member
Joined
Jun 19, 2007
Messages
3
Programming Experience
Beginner
This part of the page calls this below and i get the error:
{"Invalid attempt to Read when reader is closed.}


HTML:
<td align="right" style="width: 145px" valign="top">
                <strong><span style="color: maroon">Choose A UIC:</span></strong></td>
            <td align="left" valign="top" style="width: 236px">
                <asp:ListBox ID="lstUICs" runat="server" AppendDataBoundItems="True" DataSourceID="UICList"
                    DataTextField="UICdashCommand" DataValueField="UIC" Width="393px">   
                
                </asp:ListBox><asp:ObjectDataSource ID="UICList" runat="server" SelectMethod="UICsWithInv" TypeName="inventoryDAL">
        </asp:ObjectDataSource>

            </td>

This below is the function being called:

VB.NET:
  Public Function UICsWithInv() As List(Of uic)
        'checking to see if any inventory in database for a specific uic.  
        Dim results As New List(Of uic)()
        Try
            Dim reader As SqlDataReader
            'Dim sqlcheck As String

            ''checking to see if this item is in inventory  
            ''jls returning null - and giving error if no records.  changed to 0 if null
            'sqlcheck = "select distinct(a.uic), b.commandname from inventory a left join uiclisting b" & _
            '    " on a.uic=b.uic order by a.uic "

            'Me.m_Command.CommandText = sqlcheck

            Me.m_Command.CommandText = "usp_GetUICWithInventory"
            Me.m_Command.CommandType = CommandType.StoredProcedure
            Me.m_Command.Parameters.Add(New SqlParameter("@UserName", CheckNull(HttpContext.Current.Session("UserID"))))

            reader = Me.m_Command.ExecuteReader()

            While reader.Read
                Dim uicinfo As New uic()
                uicinfo.UIC = reader("uic")
                uicinfo.UICdashCommand = reader("uic") & "-" & reader("commandname")
                results.Add(uicinfo)
            End While
            reader.Close()

        Catch excpSQL As System.Data.SqlClient.SqlException
            TransactionRollback()
            Throw New Exception(excpSQL.ToString())

        Catch excpSystem As System.Exception
            TransactionRollback()
            Throw New Exception(excpSystem.ToString())

        Finally
            Me.m_Command.Parameters.Clear()

        End Try
        Return results

    End Function

any help would be great
 
Last edited by a moderator:
Back
Top