Invalid attempt to call FieldCount when reader is closed.

Posted on 2012-08-16
Last Modified: 2012-08-21

Im populating a gridwiew with an object. The object is a shopping cart with cartitem objects in it.

grdwCart.DataSource = Cart.CartItems;

Open in new window

I have done this other places in the site, and it has worked.

Now i have copied the same code to another place and i get this message: Invalid attempt to call FieldCount when reader is closed. I guess it has to be something that i missed when copying. It would just help alot if i understood the error message.

I don,t know what that means?
Question by:Haugenwebdesign
    LVL 43

    Assisted Solution

    At a guess you haven't opened the datasource - ie.  You haven't copied all of the relevant code.
    LVL 20

    Expert Comment

    What is Cart.CartItems?

    Is it the datareader?

    Accepted Solution

    I made one small mistake.

    I had:

    grdwShoppingCart.DataSource = shoppingCart.CartItem;

    Open in new window

    I did this to make it work

    grdwShoppingCart.DataSource = shoppingCart.CartItem;

    Open in new window


    Thanks for the help.

    Author Closing Comment

    Because this was the solution I ended up using, and it worked for me.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now