RSM
RSM

Reputation: 15108

Check if no datarows returned

I have this which check for datarows which match an expression:

DataRow[] foundRows = this.callsTable.Select(searchExpression);

How do i check if it returns some datarows, so basically if it returns none don't do what's in the if function?

I have tried:

if (foundRows != null) { }

Upvotes: 4

Views: 8850

Answers (4)

Chandan Kumar
Chandan Kumar

Reputation: 4638

check the length of the array like this

   if (foundRows.Length > 0) 
   {
        //Your code here
   }

or you can check with Count() too

   if (foundRows.Count() > 0)
   {
     //Your code here
   }

Upvotes: 0

Guilherme
Guilherme

Reputation: 5341

You can use the Count method to verify:

if (foundRows.Count() == 0)

Upvotes: 1

dav_i
dav_i

Reputation: 28107

You can do the following with LINQ

var areThereAny = foundRows.Any();

var count = foundRows.Count();

If you only want to find out whether there are any rows that match your condition, you can do the following:

var anyThatMatch = this.callsTable.Any(selectCondition);

Upvotes: 0

Adil
Adil

Reputation: 148110

You can use the Length property of array to check if you get any rows

if (foundRows.Length == 0) 

Upvotes: 9

Related Questions