Convert IEnumerable(Of DataColumn/Of Object) to System.Data.DataColumn

Hi
Now I have a template datatable with only one column. So what I am going to do is store that one column into a System.Data.DataColumn variable.

What I did:
dt.Columns.Cast(Of System.Data.DataColumn)

and this generates System.Collections.Generic.IEnumerable(Of System.Data.DataColumn)

Also tried:
Read Column which generates IEnumerable(Of Object)

Question is:
How should I convert IEnumerable(Of DataColumn/Of Object) to System.Data.DataColumn?

Hi,

DataColumn stores not data but just information for the column such as Name and Type etc.
Do you want to store only information to it?

Regards,

Hi,
I will need data for the DataColumn because what I eventually want to do is add data column to a datatable whenever it is needed. So I need a data column variable that I can pass into “Add Data Column”.

Hi,

If you want to get DataColumn variable. the following will work.

img20210908-3

However, it has just meta data of column ( doesn’t have table data).
In addition, we cannot add it to other datatable, because it’s belonged original datatable.

Regards,

Cooooool. Thank you. This works for my case.
But just in case, is it possible to convert IEnumerable(Of DataColumn/Of Object) to System.Data.DataColumn?

Hi,

As IEnumerable(Of DataColumn) is a collection of DataColumn, we can get a DataColumn using indexer (Like var(0) ) or some methods like var.First() ,var.Last() etc.

Regards,