I have a dt nameD DtConversationDT that contains a column called FirstCreatedATAsDate(datatype -system.dateTime).I need to filter out all the rows where time is less than 4 hors from current time using Linq .
I tried the below Linq but getting error as "Source contains no Data rows
currentTime As DateTime = DateTime.UtcNow
thresholdTime As DateTime = currentTime.AddHours(-4)
filteredRows = From row In DtConversationDT.AsEnumerable()
Let conversationTime = row.Field(Of DateTime)("FirstCreatedATAsDate")
Where conversationTime >= thresholdTime
Select row
If filteredRows.Any()
Then
filteredDataTable As DataTable = filteredRows.CopyToDataTable()
' Use the filteredDataTable as needed
Else
' Handle the case when no rows match the criteria
Hi, the error “Source contains no Data rows” indicates that there might not be any rows in your DtConversationDT DataTable that satisfy the condition. Once verify whether your DataTable contains data or not.
You are getting this error because no row is left after filtering datatable. For clarification, do you want to keep all the rows having time of more than now-4 hours (basically meaning processing all records of last 4 hours) or do you want all rows which are less than now-4 hours (meaning older than now-4 hours)?