2

My data looks like:

A    | B
80   | 80
90   | 10
80   | NULL

I count all non Null values of B with

.C = eGroup.Count(Function(x) x.IsBNull = False)

But I need another condition in my expression since I just want to count if A >= B.

I tried

.C = eGroup.Count(Function(x) x.IsBNull = False And x.A >= x.B)

but I get an error as soon as the B is NULL.

EDIT: I get my data from a dataset I have a field "Teams" and group my dataset by teams befor I use the query above:

dim query = From row in _dataset.DS Group row by row.Team Into eGroup = Group

ruedi
  • 5,365
  • 15
  • 52
  • 88

1 Answers1

4

Use AndAlso instead of And, the latter always evaluates also the second condition even if the first was already False. Read: What is the difference between And and AndAlso in VB.NET?

.C = eGroup.Count(Function(x) x.IsBNull = False AndAlso x.A >= x.B)

As an aside, the same applies to Or and OrElse. I've hardly ever used And or Or in 12 years of VB.NET development.

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Thanks this works great! And you also gave a great advide using OrElse and AndAlso. Thanks for that too!!! – ruedi Oct 13 '14 at 09:27