locked
Need to convert Data Table to I Enumerable without having a dedicated object RRS feed

  • Question

  • User-1188570427 posted

    I'm seeing an issue where I'm trying to convert a data table to an I Enumerable. 

    I know there is the AsEnumerable() method extension, but I keep getting the error below:

    I've followed this article: https://stackoverflow.com/questions/3392612/convert-datatable-to-ienumerablet

    Any thoughts?

    (Yes, I've already submitted a ticket to Dev Express for their assistance as well.)

            [HttpGet]
            public async Task<HttpResponseMessage> GetGridData(DataSourceLoadOptions loadOptions, int id)
            {
                DataTable dt = await DataVisualizationUtilities.GetDataVisualizationQueryResults(id);
                var dataTableConverted = dt.AsEnumerable();
                return Request.CreateResponse(DataSourceLoader.Load(dataTableConverted , loadOptions));
            }

    Error:

    2. ExceptionMessage: "'CustomerOrderNo' is not a member of type 'System.Data.DataRow'"
    3. ExceptionType: "System.ArgumentException"
    4. Message: "An error has occurred."
    5. StackTrace: " at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName) ↵ at DevExtreme.AspNet.Data.ExpressionCompiler.CompileAccessorExpression(Expression target, String clientExpr, Action`1 customizeProgression, Boolean liftToNullable) ↵ at DevExtreme.AspNet.Data.SortExpressionCompiler`1.Compile(Expression target, IEnumerable`1 clientExprList) ↵ at DevExtreme.AspNet.Data.DataSourceExpressionBuilder`1.BuildCore(Expression expr, Boolean paginate, Boolean isCountQuery, Boolean remoteGrouping, IList filterOverride, IReadOnlyList`1 selectOverride) ↵ at DevExtreme.AspNet.Data.DataSourceExpressionBuilder`1.BuildLoadExpr(Expression source, Boolean paginate, IList filterOverride, IReadOnlyList`1 selectOverride) ↵ at DevExtreme.AspNet.Data.DataSourceLoaderImpl`1.Load() ↵ at DevExtreme.AspNet.Data.DataSourceLoader.Load[T](IQueryable`1 source, DataSourceLoadOptionsBase options) ↵ at DevExtreme.AspNet.Data.DataSourceLoader.Load[T](IEnumerable`1 source, DataSourceLoadOptionsBase options) ↵ at WebPortal.MVC.Areas.DataVisualization.Controllers.DataVisualizationSmartGridController.<GetSmartGridData>d__0.MoveNext() in End of stack trace from previous location where exception was thrown --- ↵ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) ↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) ↵ at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext() ↵--- End of stack trace from previous location where exception was thrown --- ↵ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) ↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) ↵ at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext() ↵--- End of stack trace from previous location where exception was thrown --- ↵ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) ↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) ↵ at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext() ↵--- End of stack trace from previous location where exception was thrown --- ↵ at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) ↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) ↵ at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"

    Wednesday, August 14, 2019 1:23 PM

All replies

  • User665608656 posted

    Hi,

    2. ExceptionMessage: "'CustomerOrderNo' is not a member of type 'System.Data.DataRow'"

    This error message is the key to your issue. I want to know what CustomerOrderNo is.

    And could you tell us which line it thrown the error message ?

    I recommend that you can use breakpoints and F10 step by step to debug the code to see the details before this exception occurs.

    I hope you can provide us with detailed data structure of dt for reference, and this will hekp us solve your issue more eaisly.

    Best Regards,

    YongQing.

    Thursday, August 15, 2019 8:07 AM