I am filtering records using linq based on the column PROD_DATE, when the records are found there is no issue, however when there are no matching PROD_DATE it throws me an error. “The source contains no DataRows”.
That is the expected outcome, since the filtering produces zero results.
None of the entries match with today’s date (03/25/2022).
If you are wondering why you are recieveing this error, that is because a DataTable will not accept empty rows i.e., it has to contain at least one row.
To handle this, output it to a List of DataRows first, then check if the Count is greater than zero, and only then copy it to a datatable.
Thank you for that quick response and works as expected.
I did this through the conventional method, could this be achieved through same linq statement which was posted earlier.
You have handled it correctly now!
And no, the earlier LINQ statement cannot handle null exceptions which is why we have to add it to a list to validate the results before pushing it to a Datatable.