Get a cell value from DataTable



I have a simple csv file which has a header row and n amount of rows below it like this. Each row has two columns:


The amount of rows can differ but the “parameter” column’s values are always constant.

How can I read for example the value of “birthday” (which would be 07.10.1959 in this example) into a variable from this csv file? I have found some examples which are using the for each loop but I guess there could be some more powerful method which can directly point into this value? Or is there?

In real life I have hundreds of these csv files and they are quite long. Then I have very complex processes for the robots which are reading these csv files and getting some parameters for the robot during the process. The idea is to store parameters into these csv files and I or someone else could change the parameters to csv without changing the robot’s workflow. If I would use the for each loop for reading these files it would defenately strain the robot for no reason.



matchingRows = myDT.Select(“parameter = ‘birthday’”) will return an array of datarows that match this filter.
In this case to then access the date you just have to point to it:
matchingRows(0)(1).ToString will show the date as a string.



Thanks Topi! This is just what I ment and it works.

Now I can assign variables from a csv file like this
vBirthday = myDT.Select(“parameter = ‘birthday’”)(0)(1).ToString


Hi I am trying the exact same thing. My dt consists of 2 columns: Date 1 & Date 2.
Everything in column 1 is a unique date and I’m trying to extract a single corresponding Date 2 for further use but I’m getting error with the approach you described.

I’m checking for a static date right now which will be replaced by a variable.

I am getting a syntax error.

Can you please take a look?Date (54.8 KB)



if column name has spaces use sq brackets, also looks like your quotation marks were not the default ones.
I changed the assign to: datesTable.Select("[Date 1] = ‘10/5/2018’") and it worked.

Also in your message box you should determine row index and column index = date2(0)(1).ToString



Thanks very much Topi, it worked.

  1. Is there a way to pass a variable for the assign? So - datesTable.Select("[Date 1] = stringvariable")?

  2. And then to also convert the output of “date2(0)(1).ToString” to DateTime format? I need a DateTime for the rest of my process.

  1. Yes, you just have to keep the same syntax: datesTable.Select("[Date 1] = ‘" + stringVar + "’")
  2. Looks like dates in this current excel can be converted without clarifying the format so: dateVar = DateTime.Parse(date2(0)(1).ToString) works. If the format changes you can use ParseExact, and give the format of the string date you have.


Thanks Topi - works perfectly, this has been a great help!