15,741,407 members
3.00/5 (1 vote)
See more:
I have developed a report in vb.net/rdlc. what i want is to have a count of studentID for all male students(coded as 1) in grade 1.

here is what i have in rdlc

=iif(Fields!Sex.Value = 1 and Fields!grade.Value = 1,count(Fields!studentId.Value),0)

only the false part is being executed i dont know why. Would please assist me to establish where i might go wrong
Posted
CHill60 30-May-13 12:09pm
Have you tried stepping through the code in debug mode and examining the contents of the fields. There is nothing wrong with the code you've posted so it has to be the data
mayeso 30-May-13 13:21pm
but in the dataset/table these values(grade = 1 and sex =1) are there

## Solution 1

.Value is Boolean then try
if value is integer
maybe DBNull
test 1st for this

mayeso 31-May-13 13:27pm
Thanks,i tried it, it didnt work, still executing the false part

## Solution 2

put value <> 0 instead of =1
Boolean value = -1 in vb not 1

v2
mayeso 31-May-13 14:27pm
do you mean like this?
=iif((Fields!grade.Value <> 0 and Fields!Sex.value <> 0),count(Fields!studentId.Value),-1). This still returns the false part
mayeso 31-May-13 14:51pm
The query i have that is used in the dataset is generating data like this;

1 1 2009105012410059
1 1 2009105012410060
0 1 2009105012410063
0 1 2009105012410065

so in the rdlc i want to count all those with sex = 1 and are in grade 1 or vice versa, that is those with sex = 0 but are in grade 1. Like in the above sample i was supposed to get 2 for each sex

## Solution 3

The following code is test and worked
VB
```Class TItem
Public Property Sex As Integer
Public Property studentID As Long
End Class

Sub Main()

Dim Items = { _
New TItem With {.Sex = 1, .Grade = 1}, _
New TItem With {.Sex = 1, .Grade = 1}, _
New TItem With {.Sex = 0, .Grade = 1}, _
New TItem With {.Sex = 0, .Grade = 1} _
}

Dim ItemsList As New List(Of TItem)(Items)

Dim n = Aggregate Item As TItem In ItemsList Where Item.Sex = 1 And Item.Grade = 1 Into Count()

MsgBox(n)
End Sub```

v2

## Solution 4

This sql return the result too

SQL
```SELECT Sum(id)
FROM Table
WHERE sex = 1 AND grade =1 ;```

## Solution 5

`sum(iif(Fields!Sex.Value = 1 and Fields!grade.Value = 1, 1,0))`