LINQ error?

Now I use LINQ as below

InputDT.AsEnumerable.Where(Function(x)x(“สถานะ”).ToString.ToLower.Equals(“นำจ่ายสำเร็จ”)  And CInt(x(“จำนวนวัน”).Tostring) >= 15 And x(“APSTS1”).ToString <> "FLFL" And DateTime.ParseExact(x(“Issue Date”).ToString.Trim,“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture).AddYears(-543)<= ApproveDate AndAlso String.IsNullOrWhiteSpace(x(“Status”).ToString) And String.IsNullOrEmpty(x(“Chk Dup”).ToString.Trim)).ToArray

But some row in column จำนวนวัน as blank —> So it can’t convert to int —> error as below.
image

Please guide me for solve it.

Hi,

Probably it shows CInt(x(“จำนวนวัน”).Tostring) is failed due to x(“จำนวนวัน”).Tostring is empty ("").

Can you check contents of the column in your datatable?

Regards,

@Yoichi Yes, Some row in column จำนวนวัน is empty.

How to edit LINQ?

Hi,

Can you try to modify as the following?

from
CInt(x(“จำนวนวัน”).Tostring) >= 15

to

((not String.IsNullOrEmpty(x(“จำนวนวัน”).Tostring))  AndAlso CInt(x(“จำนวนวัน”).Tostring) >= 15)

Regards,

1 Like

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