How to get all values of data column in a datat table

Hi ,
Can any one please help me how to select or copy a complete column from a data table to an array

You can do something like this

dt=dt.DefaultView.ToTable(false,"ColumnName")

Thanks,
Prankur

1 Like

please check this out:

var arrColVal = dt.AsEnumerable().Select(obj => obj.Field<string>("COLUMN_NAME")).ToArray();
foreach(var colVal in arrColVal)
 {
      //do something
 }
3 Likes

@Prasanna.Ui

strArray= (From p In dta.Select
               Select Convert.ToString(p("ColumnName")).ToArray

Regards,
Mahesh

1 Like

Hi Mahesh,
Thank you for rply.
Can you please tell me what is ‘p’ in above syntax ?and can i use 2 times select in syntax ?

Hi,
Thank you for reply.
I have used your expression but i am getting below validation error.
Can you please tell me what i have missed in it. what is ‘obj’ here i am getting validation at that point.

dt - is my table name
unit1VIN - is my column name.

Hi Prasanna,

Its a C# lambda expression. Convert it to VB. It will work. obj is row here.

Hi @prasanna.Ui,

Use below code to convert the column value to array
ArrayColumn= (From dr In dt.Select Select Convert.ToString(dr.item("unit1VIN")).ToArray()

Regards,
Arivu :slight_smile:

Hi,
what is dr here.

Hi @prasanna.Ui
From here dr is the datarow.

Regards,
Arivu :slight_smile:

@prasanna.Ui

Sorry for late reply, It’s like For Each loop for a Collection. p represents each element of the collection.

Regards,
Mahesh