Results 1 to 7 of 7

Thread: [RESOLVED] Using AsEnumerable for a DataTable in .NET 6?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2022
    Posts
    83

    Resolved [RESOLVED] Using AsEnumerable for a DataTable in .NET 6?

    I am converting a .NET Framework Winforms app into a .NET 6 project, and there is an error code that states "AsEnumerable is not a member of DataTable." My guess is LINQ is modified or unusable in .NET 6?


    Code:
    Dim tarCols(numfields - 1) As String
    
    For i = 1 To numfields
       tarCols(i - 1) = Trim(FieldNames(i))
    Next
    
    Dim arrayOfObjects As Object()()
    
    Try
      arrayOfObjects = dt.DefaultView.ToTable(False, tarCols).AsEnumerable().Select(Function(x) x.ItemArray).ToArray()
    Catch
      'my exception code
    End Try
    Last edited by pel11; Jan 15th, 2023 at 04:11 PM.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: Using AsEnumerable for a DataTable in .NET 6?

    Quote Originally Posted by pel11 View Post
    I am converting a .NET Framework Winforms app into a .NET 6 project, and there is an error code that states "AsEnumerable is not a member of DataTable." My guess is LINQ is modified or unusable in .NET 6?


    Code:
    Dim tarCols(numfields - 1) As String
    
    For i = 1 To numfields
       tarCols(i - 1) = Trim(FieldNames(i))
    Next
    
    Dim arrayOfObjects As Object()()
    
    Try
      arrayOfObjects = dt.DefaultView.ToTable(False, tarCols).AsEnumerable().Select(Function(x) x.ItemArray).ToArray()
    Catch
      'my exception code
    End Try
    It should work just fine, make sure you have referenced and imported the relevant Linq libraries etc.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2022
    Posts
    83

    Re: Using AsEnumerable for a DataTable in .NET 6?

    Thanks, I was going to come back and delete this post since it eventually worked by itself. It seems like there is a learning period during which VS 2022 tries to learn and then repair issues, or is this not true(?). I did have to add "Data." in front of any DataTable, DataView, and DataRow definitions, and it seems that everything is working. Did MS add DataTable functionality to .NET 6 last year sometime?
    Last edited by pel11; Jan 15th, 2023 at 04:13 PM.

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: Using AsEnumerable for a DataTable in .NET 6?

    Quote Originally Posted by pel11 View Post
    Thanks, I was going to come back and delete this post since it eventually worked by itself. It seems like there is a learning period during which VS 2022 tries to learn and then repair issues, or is this not true(?). I did have to add "Data." in front of any DataTable, DataView, and DataRow definitions, and it seems that everything is working. Did MS add DataTable functionality to .NET 6 last year sometime?
    DataTable has always been in .Net 6, I think it was even there in .net core 1.0

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Using AsEnumerable for a DataTable in .NET 6?

    There is no learning period for the IDE. Only for the developer. If you have to use Data.DataTable where you previously used DataTable, that simply means that you haven't imported the System.Data namespace. .NET Core projects (.NET 5 and later are based on .NET Core) will not necessarily reference the same libraries and import the same namespaces by default that .NET Framework projects did. You should already be well-acquainted with the .NET documentation and know that the topic for each type tells you exactly what assembly it's declared in and what namespace it's a member of for each version of .NET, so you simply have to open the documentation for a type and read that information, then ensure that you have referenced that assembly (which is generally done by installing a NuGet package in .NET Core) and imported that namespace. I think the assembly reference should be there by default, part of Microsoft.NETCore.App, but if you had to qualify the names of types in the System.Data namespace, that would be why you couldn't access extensions methods in that same namespace.
    Last edited by jmcilhinney; Jan 15th, 2023 at 06:37 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2022
    Posts
    83

    Re: Using AsEnumerable for a DataTable in .NET 6?

    Got it, thx.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2022
    Posts
    83

    Re: [RESOLVED] Using AsEnumerable for a DataTable in .NET 6?

    Got it, thx.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width