2011-02-17 68 views
0

我有一個列類型int,我想檢查值來顯示字符串,而不是數字。需要報告表達式的幫助 - RDLC

我加入這個表達式

=IIf(Fields!Categ.Value = 1, "First", "") 
=IIf(Fields!Categ.Value = 2, "Second", "") 
=IIf(Fields!Categ.Value = 3, "Third", "") 
=IIf(Fields!Categ.Value = 4, "Fourth", "") 
=IIf(Fields!Categ.Value = 5, "Fifth", "") 

,但它無法正常工作。

我該怎麼辦?

回答

2

你可以試試嗎?

=Switch(
    Fields!Categ.Value = 1, "First", 
    Fields!Categ.Value = 2, "Second", 
    Fields!Categ.Value = 3, "Third", 
    Fields!Categ.Value = 4, "Fourth", 
    Fields!Categ.Value = 5, "Fifth", 
    Fields!Categ.Value > 5, "", 
    Fields!Categ.Value < 1, "", 
) 
+0

可怕的答案,甚至沒有解釋或試圖找出他做錯了 – 2012-07-09 08:54:31

0

我相信由.value條件返回的值是字符串,因此您可以轉換它們或進行字符串比較。

字符串比較 = IIF(字段!Categ.Value == 「1」, 「第一」, 「」)

詮釋鑄 = IIF(Int.Parse(字段!Categ.Value)== 1,「First」,「」)

自從我與RDLC合作以來,這已經有一段時間了。

0

要將嵌入式代碼添加到報告中,請使用報告屬性對話框的代碼選項卡。您創建的代碼塊可以包含多個方法。嵌入式代碼中的方法必須用Microsoft Visual Basic編寫,並且必須是基於實例的。

因此,例如:

public function getDescription(cat as integer) as string 

dim sRet as string 

select case cat 

    case 1: sRet = "first" 

    case 2: sRet = "second" 

    case else 

    sRet = "uh?" 

end select 

return sRet 

end function 

then use the expression: 

=code.getDescription(fields!Categ.value)