Error DataTable's DataRow 0

dt.AsEnumerable.Where(
Function(r) Convert.ToInt32(r(“Status”).ToString) = 0 Or Convert.ToInt32(r(“Status”).ToString) >= 3
).CopyToDataTable​

Result : No DataRow in source. /소스에 DataRow가 없습니다.

Is there a solution?

1 Like

@sumouse

This probably means you don’t have any data in your DT that satisfy the conditions you’ve specified in the Where condition. Kindly check your Excel file.

HI,

Can you try as the following?

arrDr = dt.AsEnumerable.Where(Function(r) Convert.ToInt32(r("Status").ToString) = 0 Or Convert.ToInt32(r("Status").ToString) >= 3).ToArray

Then check arrDr.Any

note: arrDr is DataRow array type

Regards,

@sumouse

dt.AsEnumerable.Where(Function(r)
statusValue As String = r(“Status”).ToString().Trim()

numericValue As Integer
If Integer.TryParse(statusValue, numericValue) Then
Return numericValue = 0 Or numericValue >= 3
Else
Return False
End If
End Function
).CopyToDataTable()

if condition
dt1.AsEnumerable.Any(Function(x) Cint(x(“Status”).ToString)=0 Or Cint(x(“Status”).ToString) >= 3)

then part use assign
dt1.AsEnumerable.Where(Function(x) Cint(x(“Status”).ToString)=0 Or CInt(x(“Status”).ToString)>=3).CopyToDataTable

else part i.e, when there are no rows with your requirement you can add amessage stating no data or whatever the steps required to be followed if no data exists matching to your requirement

thank you ^^~

Thank you for your kindness.

Thank you for your kindness.

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