Invalid attempt to call FieldCount when reader is closed.

Hello.

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

grdwCart.DataSource = Cart.CartItems;
DataBind();

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?
HaugenwebdesignAsked:
Who is Participating?
 
HaugenwebdesignAuthor Commented:
I made one small mistake.

I had:

grdwShoppingCart.DataSource = shoppingCart.CartItem;
DataBind();  

Open in new window


I did this to make it work

grdwShoppingCart.DataSource = shoppingCart.CartItem;
grdwShoppingCart.DataBind();  

Open in new window


grdwShoppingCart.DataBind();

Thanks for the help.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
At a guess you haven't opened the datasource - ie.  You haven't copied all of the relevant code.
0
 
Obadiah ChristopherCommented:
What is Cart.CartItems?

Is it the datareader?
0
 
HaugenwebdesignAuthor Commented:
Because this was the solution I ended up using, and it worked for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.