Invalid attempt to call FieldCount when reader is closed.

3 posts, 0 answers
  1. Paul J
    Paul J avatar
    101 posts
    Member since:
    Nov 2008

    Posted 09 Jun 2010 Link to this post

    keep getting:

    Invalid attempt to call FieldCount when reader is closed.

    calling rlv.Rebind() on page load.

    <telerik:RadListView ID="rlv" OnNeedDataSource="rlv_NeedDataSource" ItemPlaceholderID="ProductItemContainer" runat="server"
                <LayoutTemplate> 
                 
                    <fieldset> 
                        <legend>Parent Contacts</legend> 
                        <table cellpadding="0" cellspacing="0" class="tblDisplay" width="auto"
                        <tr> 
                            <td>Name</td> 
                            <td>Relation</td> 
                            <td>Phone</td> 
                            <td>Work #</td> 
                            <td>Cell #</td> 
                        </tr> 
                        <asp:PlaceHolder ID="ProductItemContainer" runat="server" /> 
                        </table> 
                    </fieldset> 
                </LayoutTemplate>             
                 <ItemTemplate> 
                     <tr> 
                        <td><%#DataBinder.Eval(Container.DataItem, "FullName")%>"</td> 
                        <td><%#DataBinder.Eval(Container.DataItem, "RelationDesc")%>"</td> 
                        <td><%#DataBinder.Eval(Container.DataItem, "Phone")%>"</td> 
                        <td><%#DataBinder.Eval(Container.DataItem, "WorkPhone")%>"</td> 
                        <td><%#DataBinder.Eval(Container.DataItem, "CellPhone")%>"</td> 
                     </tr> 
                </ItemTemplate>             
                </telerik:RadListView> 

    .List() below returns a datareader.
            Protected Sub rlv_NeedDataSource(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadListViewNeedDataSourceEventArgs) Handles rlv.NeedDataSource 
     
                Dim sqlDR As SqlDataReader 
                sqlDR = ObjectTest.List() 
                rlv.DataSource = sqlDR 
            End Sub 





  2. Rosen
    Admin
    Rosen avatar
    3235 posts

    Posted 11 Jun 2010 Link to this post

    Hello Paul,

    Can you please verify that neither the DataReader nor the underlining DataConnection is closed while RadListView is databinding. The best place to close the connection and reader in this case will be inside RadListView DataBound event. You may take a look at this online demo for a runnable sample.

    Sincerely yours,
    Rosen
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul J
    Paul J avatar
    101 posts
    Member since:
    Nov 2008

    Posted 16 Jun 2010 Link to this post

    Thanks, That was the problem. My ObjectTest.List() returns a sqldatareader. This .List() function exists within a business class. Because of this setup, I guess the sqldatareader the .List() function returns gets closed after the list control binds to it? and binding that to a radListView doesn't allow me to close the sqldatareader within the list's databind event instead.

    I had to change the code so that instead of binding it to the object class's .List function, I had to create a different sqldatareader, loading it , etc. on the same code level as where I bind the list to the sqldatareader, so I have direct access to this reader in the radListView's databind event to close the sqldatareader. For cleaniless of code, I'd rather not do this. I'm not sure why the radListview has an issue with binding to my object class's .List function when the radGrid doesn't. So I ended up using a radGrid for what I need instead of the radListView.

    Thanks though...
Back to Top