Problem is with CopyToDatatable(). This method only works for collection with at least one row.
To ensure that the method does not return an error you can use if statement with a condition that check if there is at least one row after the filter:
Instead of CopyToDaTatable first check if count>0 in an if condition if yes then use .copytodatatable else use dt.Clone which will just clone the original datatable with no rows and no error would throw
The error message “the source contains no data rows” in the given VB.NET code usually indicates that the dt1 or dt2 data table is empty or does not contain any data rows.
To fix this issue, you can try the following:
Make sure that dt1 and dt2 are populated with data before running the code. You can check the number of rows in each data table using the Rows.Count property.
Make sure that the column names specified in the Select and Where clauses are correct and exist in the data tables.
Make sure that the data type of the columns specified in the Field(Of String) method is correct. If the data type is not String, you may need to use a different method, such as Field(Of Integer) or Field(Of DateTime), depending on the data type of the column.