Creating a new datatable with concatenated values from various columns without for each

Hi,

I have a data table with around 20,000 rows that contain 3 columns as shown in the screenshot(EmailID, balance, Company). I want to create a new data table with columns as “Email ID” and “Message body” where the “Message body” would be generated from a predefined text by replacing the “balance” and “company name”.

The output datatable should look as shown below with the content highlighted in red are replaced from “balance” and "Company for each row.

image

As the input data table has 20,000 rows, using a for each is very time-consuming.

Can anybody please suggest a faster solution using invoke code?

Thanks,
Amrutha

Hi,

How about the following?

dtResult = dtInput.AsEnumerable.Select(Function(r) dtResult.LoadDataRow({r("Email ID").ToString,String.Format(strTemplate,{r("Balance").ToString,r("Company").ToString})},False)).CopyToDataTable()

Sample20221211-1aL.zip (2.9 KB)

Regards,

1 Like

@Yoichi Thank you. This worked.

1 Like

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