The source contains no datarow - error

Hello :slight_smile: Can I add a condition to this sentence that if there is nothing in the data table then do nothing?

dt_nieobecnosci.AsEnumerable().Where(Function(X) DateTime.ParseExact(X(“Koniec”).ToString(), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) > DateTime.Now).CopyToDataTable()

I get an error: the source contains no datarow

Hello @sullivanne

You could use an If-sentence and check the rowcount:

If(dt_nieobecnosci.AsEnumerable().Where(Function(X) DateTime.ParseExact(X(“Koniec”).ToString(), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) > DateTime.Now).RowCount>0,dt_nieobecnosci.AsEnumerable().Where(Function(X) DateTime.ParseExact(X(“Koniec”).ToString(), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) > DateTime.Now).CopyToDataTable(), Nothing)

Regards
Soren

1 Like

@sullivanne,

You can split the logic like this.

Get the data rows filtered first using this:

filteredRows = dt_nieobecnosci.AsEnumerable().Where(Function(X) DateTime.ParseExact(X("Koniec").ToString(), "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture) > DateTime.Now)

Once filtered, use If activity to check if they are any rows or not like this:

If filteredRows.Any() Then
    dt_nieobecnosci = filteredRows.CopyToDataTable()
Else
    ' Handle the case where there are no rows, e.g., log a message or do nothing
    Console.WriteLine("No rows found matching the condition.")
End If
1 Like

Thank You very much and Happy Birthday to You! :birthday:

1 Like

:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

1 Like

Thanks a lot @sullivanne :heart: Cheers!

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