Assign Primary Keys to Data Table

I’m using the build data table activity and need to output a table with multiple keys. It doesn’t look like this can be done with the build data table activity alone. Does anyone know how to achieve this?

@bcarp you can find examples in thé following post Comparing two data tables

Silviu or @tdhaene Can you explain how I would use your solution for setting primary keys to set only some fields as keys?

Hi,

First add a key like:

YourDatatable.PrimaryKey = new DataColumn() { yourDatatable.Columns(“id”) };

Next do invoke method AcceptChanges

4 Likes

Thank you. Can you tell me what I’m doing wrong here?PK1

add_primaryKey.xaml (7.4 KB)
@bcarp Here you have the snippet

if you use named columpns or multiple values: use new datacolumn() {dt.Columns(“Column0”),dt.Columns(“Column1”)} as the value.

If this helps don’t forget to mark sthis as solution so other users can retrieve the solution

kind regards,

Tom

2 Likes

I’m still getting errors as to the method. I’ve tried dt.columns and dt as the target object along with AcceptChanges and ApplyChanges. Please see attached.PK4

It seems to me that your variable is not of the type datatable but datacolumncollection.

In my posted example you can find the proper types

1 Like

I see that the " sign for the first column (edc) is not a correct one. paste the value in notepad to correct the correct char. @bcarp

1 Like