|
-
Jan 15th, 2023, 02:39 PM
#1
Thread Starter
Lively Member
[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.
-
Jan 15th, 2023, 03:13 PM
#2
Re: Using AsEnumerable for a DataTable in .NET 6?
 Originally Posted by pel11
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.
-
Jan 15th, 2023, 04:08 PM
#3
Thread Starter
Lively Member
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.
-
Jan 15th, 2023, 06:09 PM
#4
Re: Using AsEnumerable for a DataTable in .NET 6?
 Originally Posted by pel11
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
-
Jan 15th, 2023, 06:25 PM
#5
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.
-
Jan 15th, 2023, 06:43 PM
#6
Thread Starter
Lively Member
Re: Using AsEnumerable for a DataTable in .NET 6?
-
Jan 15th, 2023, 06:44 PM
#7
Thread Starter
Lively Member
Re: [RESOLVED] Using AsEnumerable for a DataTable in .NET 6?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|