Hello 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
SorenB
January 7, 2025, 6:53pm
2
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!
1 Like
ppr
(Peter Preuss)
January 8, 2025, 4:44pm
5
1 Like
Thanks a lot @sullivanne Cheers!
system
(system)
Closed
January 11, 2025, 6:26pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.