Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:37+00:00 2026-05-26T15:26:37+00:00

I am fairly new to Entity framework as well as LINQ. I have used

  • 0

I am fairly new to Entity framework as well as LINQ. I have used DataGridView before and to set the datasource to it

DataGridView1.datasource=dt; // dt=datatable

was enough. But while reading ASP.Net book they have given the code using Entity Framework as

using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
{
    var allGenres = from genre in myEntities.Genres
    orderby genre.Name
    select new { genre.Name, genre.Reviews };
    GridView1.DataSource = allGenres;
    GridView1.DataBind();
}

Why is this DataBind()is used in the end. I have seen the MSDN document forDataBind()which says “(It) Binds a data source to the invoked server control and all its child controls.”

And if I remove it, I get an error as “The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.”

So I was just confused that what is thisDataBind()actually does? I have seen some people using DataBind for DataGridView also, and I am not sure why?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:26:37+00:00Added an answer on May 26, 2026 at 3:26 pm

    The DataBind method forces the datasource to be read and bound to the control. Since you databind within the PlanetWroxEntities context which you dispose afterwards, the control should read the data from the datasource before the PlanetWroxEntities disposes. In other words: before the database connection is closed.

    A alternative is to force the query by calling the .ToList() method. This sets the DataSource property to a non-lazy list containing the concrete data.

    using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
    {
        var allGenres = from genre in myEntities.Genres
        orderby genre.Name
        select new { genre.Name, genre.Reviews };
        GridView1.DataSource = allGenres.ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still fairly new to Entity Framework (currently developing using v4.1), so I may
I am fairly new to Entity Framework and investigating converting some legacy data access
I am using the Entity Framework 4.2 and I have a fairly serious performance
I am fairly new to entity framework and I want to know what is
I'm fairly new to entity framework and patterns. How would I insert data into
I am fairly new to the MVC Framework and have spent the last few
I am new to fairly new to AS3 and I have found myself needing
I am fairly new to php and mysql but I have created a small
I'm fairly new to C++ standard library and have been using standard library lists
Being new to the Entity Framework, I'm really rather stuck on how to proceed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.