SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software

Development Forums for Programmer, Administrators and Users

Development resources, articles, tutorials, code samples and tools and downloads for ASP.Net, SQL Server, R Script, Windows, Windows Phone, AWS, SAP HANA and ABAP, like SAP UI5, Screen Personas, etc.

"The query results cannot be enumerated more than once." error during dcDataContext.ExecuteQuery(Of T) method call

Last post 05-18-2009, 8:47 AM by eralper. 1 replies.
Sort Posts:
  •  05-18-2009, 8:23 AM 10208

    "The query results cannot be enumerated more than once." error during dcDataContext.ExecuteQuery(Of T) method call

    Hello,

    I get the following error message when I'm trying to bind the data to a datagrid which is returned by the DataContext.ExecuteQuery(Of T) method.

    Here is the code. The first code is being executed to get data to bind the gridview

    Dim productList As IEnumerable(Of Product)
    productList = dcDataContext.ExecuteQuery(Of Product)("SELECT * FROM Product")

    The second code is executed on the rowcreated event of the data gridview.

    Dim customerList As IEnumerable(Of Customer)
    customerList = dcDataContext.ExecuteQuery(Of Customer)("SELECT * FROM Customer")

    And the error is as follows :

    The query results cannot be enumerated more than once.

    at System.Data.Linq.SqlClient.SqlProvider.OneTimeEnumerable`1.GetEnumerator()
    at System.Data.Linq.SqlClient.SqlProvider.OneTimeEnumerable`1.System.Collections.IEnumerable.GetEnumerator()
    at System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource)
    at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
    at System.Web.UI.WebControls.ListControl.PerformSelect()
    at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
    at System.Web.UI.Control.DataBindChildren()
    at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
    at System.Web.UI.Control.DataBind()
    at System.Web.UI.Control.DataBindChildren()
    at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
    at System.Web.UI.Control.DataBind()
    at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
    at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
    at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
    at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
    at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
    at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
    at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
    at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
    at System.Web.UI.WebControls.GridView.DataBind()

  •  05-18-2009, 8:47 AM 10209 in reply to 10208

    Re: "The query results cannot be enumerated more than once." error during dcDataContext.ExecuteQuery(Of T) method call

    OK, I have found the solution for the Enumeration problem I faced in my ASP.NET codes.

    The query results cannot be enumerated more than once.


    While getting the IEnumerable list data for the Customesr and the Products using DataContext.ExecuteQuery(Of T) method, I used the ToList() extension.


    Dim productList As IEnumerable(Of Product)
    productList = dcDataContext.ExecuteQuery(Of Product)("SELECT * FROM Product").ToList

    Dim customerList As IEnumerable(Of Customer)
    customerList = dcDataContext.ExecuteQuery(Of Customer)("SELECT * FROM Customer").ToList


View as RSS news feed in XML
Copyright © 2004 - 2019 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems