How to get whole 1st line from datatable?

Hi all,

Please can you help me with the expression I need to write in an assign activity to get the first row from my data table.

It has two columns so I want to get the data from both columns.

I can see that ExtractDataTable.Rows(0).Item(0) would extract the 1st row and first column value (e.g “baked beans”. How do I modify this expression to get the value from the second column as well? (e,g “baked beans 24p”

Thinking about it, how would I do this so the two values remain in separate columns so I can paste them in to an excel file as two columns?

Thanks
Jordan

2 Likes

@jordrowley - You mean need to fetch first row from the datatable ?

Hello @jordrowley

ExtractDataTable.Rows(0).Item(0) you can first column value
ExtractDataTable.Rows(0).Item(1) second column

Thanks

4 Likes

Hi @jordrowley ExtractDataTable.Rows(0).Item(0).ToString+ExtractDataTable.Rows(0).Item(1).ToString

2 Likes

use Datatable.rows(0) this will give you the first row in the datatable.

1 Like

Fine
you were almost done
it should be like
String,Join("_",ExtractDatatable.Rows(0).ItemArray)
the output will be like
columnvalue1_columnvalue2
in a single step and if we want to paste this in another excel
pass like this
ExtractDatatable.Rows(0)(“columnname1”)
ExtractDatatable.Rows(0)(“Columnname2”)

Cheers @jordrowley

2 Likes

Hey @Palaniyappan

Thank you when I’ve got my two values in two assign stages (one for each column) how to do I add them both to a new data table, please?

Thanks
Jordan

1 Like

Hi everybody

Thank for you replying, appreciate the solutions offered to me :slight_smile:

Jordan

1 Like

Fine no worries
If we have them two assigned values then we can add them to the new datatable using ADD DATA ROW activity
where in the arrayrow property mention like this {variable1,variable2}
and in the datatable mention the datatable variable name

Cheers @jordrowley

1 Like

Hey @Palaniyappan

Brilliant, thank you. One last cheeky question please. How do I empty the original data table? Because it is in a For Each loop and I want to empty it ready to search the next item on my shopping list and take the same steps around getting the first value from the data table etc

Thanks
Jordan

1 Like

Hey @sandipauti, Yes, the first row. Thanks for replying, other people have provided the solution for me :slight_smile:

Thanks
Jordan

No worries
use CLEAR DATATABLE activity and pass the datatable so that it will clear all the data and we will be having only the header
Cheers @jordrowley

1 Like

@Palaniyappan

When I assign my two variables and then use the add data row to add them to my new data table (which I have initialised using ‘New System.Data.DataTable’) I get this error

CaptureDT

This is how it is set up

Please can I ask if you know why I am getting this error? Is it bacause I somehow need to specify that my new initialised data table needs to have two columns in it?

Thanks for all the help

Jordan

1 Like

@jordrowley - You can only pass array to Add Data row activity. e.g array = {variable1, variable2}

Pass this array as input to data row.

Thanks @sandipauti, the two items I need are in string variables at the moment. Do you know I covert them in to an array so I can then pass that in as a data row?

Thanks for the reply
Jordan

1 Like

@jordrowley - Suppose you store first string variable as String1 and second as String2 then you can create third variable arr as array of string and assign the value to variable

arr = {String1, String2}

1 Like

No worries

Yah certainly, We need to make sure that the number of values passed in the ArrayRow should be equal to the number of columns in our datatable that we have mentioned inthe datatable property of add data row…

Cheers @jordrowley

1 Like

This was great thank you - worked perfectly

1 Like

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