Question

Add DataRow into LookupTable

Hi

How can I add a new DataRow into a LookupTable or a DataTable?

Correct Answer
November 14, 2019 - 6:05pm

You'd be performing these operations on the DataTable, so C# code would be best. A DataTable has both a Merge and an ImportRow method. The merge is faster and takes the two tables and essentially glues them together. If you want to import only specific rows, you can use the ImportRow method.

Here's a sample solution where I use both. Button 1 will use Merge and button 2 will use the ImportRow.

Comments

Keep up to date on this post and subscribe to comments

Pega
November 14, 2019 - 8:29am

If you are using a LookupTable, there's an AddRecord method that allows you to add a new row. If you have used the DataTable from the LookupTable and wish to manipulate that (for example; you called GetTable to extract the DataTable object), you could add a DataRow object into that DataTable and then call ReplaceTable on the LookupTable to put it back.

The LookupTable is really designed to abstract the underlying DataTable, so in an automation, it is easier to use its methods than getting at the underlying DataTable.

November 14, 2019 - 9:00am
Response to tsasnett

In my case I have two tables from different files, but with the same columns, so in the first time I can make the ReplaceTable on LookupTable but the second time I need to make an append, I can not replace, I need to join these tables.

Using the AddRecord I have to pass column by column and this makes the process slow.

There is another way to add a DataRow like only one parameter instead to pass column by column?

November 14, 2019 - 9:03am
Response to tsasnett

How can I add a DataRow into the DataTable?

Pega
November 14, 2019 - 6:05pm

You'd be performing these operations on the DataTable, so C# code would be best. A DataTable has both a Merge and an ImportRow method. The merge is faster and takes the two tables and essentially glues them together. If you want to import only specific rows, you can use the ImportRow method.

Here's a sample solution where I use both. Button 1 will use Merge and button 2 will use the ImportRow.

November 18, 2019 - 7:25am
Response to tsasnett

Thank you. That's what I need.