Reading CSV using column name

Hi everyone,

I need to read a CSV file and get the required columns’ data using column name. The rows can 1 or more than one.

Eg.:

Name;Age;Country;Gender;Pass
Mike;19;USA;M;Yes

Need to get the 3 values highlighted in bold using the column name and there can be multiple rows like below.

Name;Age;Country;Gender;Pass
Mike;19;USA;M;Yes
Schul;21;Germany;M;No

@alpharobot,

Use the read CSV activity, and then a for each row to go through each row item in DataTable.
You can then use row("ColumnName").ToString() to access each row item in that column.

1 Like

use assign activity with following
datatableName.DefaultView.ToTable(False,{“Name”,“Country”,“Gender”})
if you want distinct values among those 3 columns, replace False with True

1 Like

You can even try with Filter Datatable Activity where you can mention the Column Names to keep and assign it to a Datatable.

2 Likes

Agreed…!!
if they are not using the older Studio which doesn’t support this activity

2 Likes

Hi @SenzoD

Tried using the for each loop for datatable but getting this error.

image

HI @Gurram_Akhil

Used this solution but I am getting output as a word “Datatable” as text. I made the value True and tried storing in a variable of string type.\

image

Can you tell the datatype of the variable to store this output?

Hi @hasib08

But after the required value are in datatable how to extract it in individual string variables?

Use For each row in Datatable_Variable and inside for each row, you can assign it to individual string variables.
Like this
name = row(“yourcolumnname”).ToString
Or
name = row(columnindex).ToString
Where column index starts from 0 for first column in excel

Thanks for the reply, @hasib08

Can you help me this error?

I think the cause for the error is you used “For Each” to loop through the datatable, where you should use “For Each Row” to loop through the datatable.
To show the values you could use something like a writeline with this statement: row("Name").ToString() + ", " + row("Country").ToString() + ", " + row("Gender").ToString()

I built a datatable like yours, and looped through the rows. Please let me know if this helped.

image

image

2 Likes

@Jeroen

Thanks a lot for the effort to give the solution. It worked absolutely fine.

Thanks @SenzoD, @Gurram_Akhil and @hasib08 for the help. :slightly_smiling_face:

2 Likes

Hi,
Datatype of the variable to be stored is DATATABLE.
to print values you might need to use Writerange in Excel or use ForeachRow

1 Like

Got i!

Thanks for the reply, @Gurram_Akhil

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.