Getting the value of a particular column from datatable without using for each row

Hi,
I have a data table and I need to fetch the data from the particular column
Actually I am using 2 data tables and from the 3rd data table I need to get the data from the particular column.
How to do it?

1 Like

@Kunal_Jain ,
Try this

InputDT.DefaultView.ToTable(False,"YourColumnName")

This will return a single column from your DataTable

Regards,

Hi

To get data from one specific column and row

Stroutput = dt.Rows(rowindex)(“yourcolumnname”)

To get one entire column as a list of string

Stroutput = ( From row in dt.AsEnumerable() Select Convert.Tostring(row(“ColumnName”)) ) .ToList()

For all functionalities in datatable have a view on this tutorial

Cheers @Kunal_Jain

2 Likes

It is giving output as tablename
not the required output

Hi @Kunal_Jain

Use a For Each Row activity to iterate through the rows in the “dt3” data table.

Within the loop, use the Get Row Item activity to retrieve the value from a specific column.

The Get Row Item activity takes two parameters: the first parameter is the data table variable, and the second parameter is the name or index of the column you want to retrieve the value from.

Thanks!!

I don’t have to use for each activity just to iterate one column

Try this-

dtSelected = dt3.DefaultView.ToTable(False, “ColumnName”)

Thanks!

@Kunal_Jain ,
It will provide a single Column .
you assigned it to the DataTable Right?
Put like This
DT_YourColumn =DT_Input.DefaultView.ToTable(False,"YourRequiredColumnName")

Here DT_YourColumn is the Output of type DATATABLE
and DT_Input is your Input DATATABLE

Regards,

1 Like

but to pass it in add data row I again need to pass it through for each row right??

@Kunal_Jain ,
According to your requirement you need only one entire Column from your actual datatable right?
For that you need not do for each row you will get by doing the above method.
By the way why you are doing add data row?
Also If possible please share the sample input and the expected output

Regards,

Well I need to pass the columns value into add data row as it contains the data for 2 datatables.
I cannot share the data

@Kunal_Jain ,
You can share the sample input Dummy Input you can create and share and the expected output.

@Kunal_Jain

May I know how many rows are there in datatable and how many values are to be passed in add datarow

A small representation or explanation about the datatable will help

If its only one rows and you need aome column data then dt.Rows(0)("ColumnName").ToString will help

Cheers