How to Add condition (LINQ)

I want to add condition in LINQ.

add condition column “APSTS1” not equal FLFL.

Now my code as below.

InputDT.AsEnumerable.Where(Function(x)x(“Status (1)”).ToString.ToLower.Equals(“complete”) And CInt(x(“Date”)) >= 15 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

Hi @fairymemay ,

Try this

`

InputDT.AsEnumerable.Where(Function(x)x(“Status (1)”).ToString.ToLower.Equals(“complete”) And x(“APSTS1”).ToString <> "FLFL" And CInt(x(“Date”)) >= 15 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

`

1 Like

Hi @fairymemay

Try this below Expression

InputDT.AsEnumerable.Where(Function(x)x(“Status (1)”).ToString.ToLower.Equals(“complete”) And CInt(x(“Date”)) >= 15 And x(“APSTS1”).ToString.Trim <> “FLFL” And DateTime.ParseExact(x(“IssueDate”).ToString.Trim,“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulure).AddYears(-543)<= ApproveDate AndAlso String.IsNullOrWhiteSpace(x(“Status”).ToString) And String.IsNullOrEmpty(x(“Chk Dup”).ToString.Trim)).ToArray

Regards
Gokul

1 Like

@Shikhar_Tandon @Gokul001
If I add more condition Time >=20
But data in column = type text

Now I use CInt(x(“Time”)) >= 20

But show error as below.
image

Please guide me for solve it.

@fairymemay
Try this expression

InputDT.AsEnumerable.Where(Function(x)x(“Status (1)”).ToString.ToLower.Equals(“complete”) And CInt(x(“Date”).Tostring) >= 15 And x(“APSTS1”).ToString.Trim <> “FLFL” And DateTime.ParseExact(x(“IssueDate”).ToString.Trim,“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulure).AddYears(-543)<= ApproveDate AndAlso String.IsNullOrWhiteSpace(x(“Status”).ToString) And String.IsNullOrEmpty(x(“Chk Dup”).ToString.Trim)).ToArray

Try to give .Tostring
CInt(x(“Time”).Tostring) >= 20

Regards
Gokul

1 Like

@fairymemay
If your issue is Solved

Kindly mark the appropriate post as solved.

Regards
Gokul

@Gokul001 Same error.

image

Hi @fairymemay

Can you check all the values in the expression are not null or empty

Regards
Gokul

@Gokul001 Yes, some row in column Date = blank

@Gokul001 Yes, some row in column Date = blank (null)

This the reason for the error @fairymemay Need to be tackle this issue

Giving condition like

Column Data <> ""

Regards
Gokul

@Gokul001 Write in LINQ?

Can you tell the column that is empty @fairymemay

@Gokul001 Column Status and Date

Try this expression

InputDT.AsEnumerable.Where(Function(x)x(“Status (1)”).ToString.ToLower.Equals(“complete”) And CInt(x(“Date”).Tostring) >= 15 And x(“APSTS1”).ToString.Trim <> “FLFL” And x(“Column Status”).ToString.Trim = “” And x(“Date”).ToString.Trim = “” And DateTime.ParseExact(x(“IssueDate”).ToString.Trim,“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulure).AddYears(-543)<= ApproveDate AndAlso String.IsNullOrWhiteSpace(x(“Status”).ToString) And String.IsNullOrEmpty(x(“Chk Dup”).ToString.Trim)).ToArray

Regards
Gokul

2 Likes

@Gokul001 same error.

But If fulfill data only column Date all rows.
It can run completed.

How to solve it?

Can you elaborate the query @fairymemay

@Gokul001 I think it error because column Date ( If blank it can’t convert to int —> error)
Because I try fulfill data in column Date (not have blank row , It can run)

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