Error: The source contains no DataRows

Hi guys,

I need to split an excel file containing source data into different csv files. Currently I read the excel file, store it in a datatable and use a for each row loop with the following expression to filter with column “ORG” and the write it to a CSV file. str_country gets values assigned dynamically.

dt_entityMaster = dt_entityData.Select(“[ORG] LIKE ‘" +str_country +"’”).CopyToDataTable

In general this works. However, it throws the error message: (Assign - The source contains no DataRows) as soon as str_country has a value which is not found in dt_entityData.

Any solution / other approach how this could be circumvented?
In this case it should just ignore it, don´t create a csv file and jump to the next country.

Thx in advance!

Hey @n.k2020,

You can first perform a check to make sure that there are rows in the datatable that match your filtering condition. This can be done using “Any” Enumerable.Any Method (System.Linq) | Microsoft Docs

If dt.AsEnumerable().Any(function(x) x("columnName").ToString.Contains(str_country))
     Filter and write the Csv
1 Like

Thx, a lot :slight_smile: Works perfectly fine.

1 Like

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