none
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported in asp.net gridview databind() RRS feed

  • Question


  • I have a the following code to fill data for my Asp.net gridview. I used the same code as below in other asp.net page to load data to gridview. All other pages are fine with the code and successfully display gridview with data. But in one page, to display product list of customer purchasing, it display error. This is my code.

    using (DataContext.DBEntities ctx = new DataContext.DBEntities())
    {
    List<DataContext.vwClientAndProduct> product = new List<DataContext.vwClientAndProduct>();
    product = ctx.SP_ClientAndProduct_Select().ToList<DataContext.vwClientAndProduct>();
    gvList.DataSource = product.ToList();
    gvList.DataBind();
    }

    I traced the code of the error page, it successfully passed gvList.DataBind() method. But when I continue F5, error message displayed in my product.aspx page. The error starts with 'Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported....'

    Each of the following is not worked too.

    var product = (from row in ctx.SP_ClientAndProduct_Select()
                                  select row).ToList();
    
    //var product = from row in ctx.SP_ClientAndProduct_Select()
                                  select row;
    //var product = ctx.SP_ClientAndProduct_Select().ToList();                   
    
    gvList.DataSource = product.ToList();
    gvList.DataBind();

    The other page is working well with the following.

    using (DataContext.DBEntities ctx = new DataContext.DBEntities ())
                {
    var product = ctx.SP_Product_Select().ToList()
                    gvList.DataSource = product.ToList();
                    gvList.DataBind();
                }

    I don't know why this is not working although the code is same.

    Please help. Thanks

    Wednesday, September 6, 2017 8:02 AM

Answers


  • It worked !

    I created a new aspx page and copy all code from error page to new page.

    When new page load, the gridview displays with data.

    Very Strange !

    Thanks.

    • Marked as answer by nyinyiaung Wednesday, September 6, 2017 9:35 AM
    Wednesday, September 6, 2017 9:34 AM