Click here to Skip to main content
15,947,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi all,

I selected a table from db and while bind gridview i am getting following error message,
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList(). For ASP.NET WebForms you can bind to the result of calling ToList() on the query or use Model Binding, for more information see http://go.microsoft.com/fwlink/?LinkId=389592.


and my code is,

public void fngetdata()
        {
            using (BASdbContext objFeeSch = new BASdbContext())
            {
                gvFeeSchedule.DataSource = from data in objFeeSch.FEE_SCHEDULE
                                           select data;
                gvFeeSchedule.DataBind();
            }
            
        }



Thanks in Advance :-)

What I have tried:

public void fngetdata()
        {
            using (BASdbContext objFeeSch = new BASdbContext())
            {
                gvFeeSchedule.DataSource = from data in objFeeSch.FEE_SCHEDULE
                                           select data;
                gvFeeSchedule.DataBind();
            }
            
        }
Posted
Updated 29-Jul-18 2:21am
Comments
james olanrewaju 17-Aug-18 4:56am    
nice

Try This...
public void fngetdata()
        {
            using (BASdbContext objFeeSch = new BASdbContext())
            {
                gvFeeSchedule.DataSource = (from data in objFeeSch.FEE_SCHEDULE
                                           select data).ToList();
                gvFeeSchedule.DataBind();
            }
            
        }
 
Share this answer
 
v2
you can use as per documentation and I tested it :)

C#
public void fngetdata()
        {
            using (BASdbContext objFeeSch = new BASdbContext())
            {
                objFeeSch.FEE_SCHEDULE.Load(); // you should add using System.Data.Entity;
                gvFeeSchedule.DataSource = objFeeSch.FEE_SCHEDULE.Local.ToBindingList<FEE_SCHEDULE>();
                gvFeeSchedule.DataBind();
            }
            
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900