How can I extract an entire row of a DataTable to save it in a variable?

Hello,

I need to save each row created in the “Generate Data Table” in a variable. For the moment I have managed to display the values ​​that are saved in the table but I have managed to paint it on the screen by making an indexed call to each column (within each row).

This may be against me because you may find rows where the “item (8) .tostring” does not exist and the code breaks,

Is there a way to make a single call for each line instead of concatenating each column?

Attached some images to illustrate the case

Hi @Yur did you try to assign the row value to a DataRow variable? Also you can run a For Each activity assigning all rows to a Array of Rows.

1 Like

Hello,

Thanks for your response but I can not visualize the answer you propose. Could you give an example? A capture or a xaml?

If I try to paint the index on the screen directly without pre-selecting each column and I get the following message on the screen

If you have any suggestions this will be welcome, thank you very much.

A greeting.

Hi @Yur,

A datarow contains many columns, if you were looking for the values represented in each column, you can get it inside the for each loop by:
item(“ColName”).ToString

When you print item.ToString, it represents the DataRow object and might not provide the individual values you’re looking for.

Hope that helps!

Regards,
PD

1 Like

Hello,

I understand that your proposal: element (“ColName”). ToString would result in the saved values ​​for that column but in my case I want to recover the saved values ​​for the whole row.

What function or syntax is optimal to obtain this result?

Thanks for your time,

A greeting.

Well you could try something like:
string.Join(",",item.ItemArray)

Regards,
PD

1 Like

Ok I understand,

Currently my “itemArray” is in “Datatable” format and to be able to use the instruction that you have requested, it must be in System.Data.DataRow format.

Do you know how I can adapt this situation?

Thank you very much in advance,

A greeting.

You could change the for each TypeArgument property to be “DataRow” type. Then your loop will be of Datarow type and have its properties.

Regards,
PD

1 Like

Hi

Finally I have not yet been able to solve this problem. sample.xaml (15.4 KB)

I have been reviewing information about this functionality but not in this way I get the values ​​making a single call instead of: item (0) .toString + “” + item (1) .toString + “” item (2) .toString … .

Attached I am sending you the .xaml with the code section in question and an image capture for you to understand with the results of String.Join (“”, test1).

Thank you very much in advance, I will appreciate any proposal.

image

Hi @Yur,

Thanks for the screenshot. Your writeline should be: String.Join(" ",item.ItemArray)

item is the variable holding each datarow; but you were passing the datatable variable name (prueba1). That’s why the results were not right.

Please try and let me know how it goes.

Regards,
PD

Hello,

Unfortunately this is not the solution. The composition of the function has been understood with its previous message but it is not accepted as valid.

If I write “test1” it gives me an error but if I only write “test” it accepts it as valid … it is as if I detect it as another optional parameter of the function.

Attached is an error capture.

Thank you very much for your involvement in solving this error.

image

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