colB.Expression = IIF(colA = stringA, 字符串, 字符串)

colB.Expression = IIF(colA = stringA, stringB, stringC)

在我的数据表中,我有两列:

With colA
            .DataType = System.Type.GetType("System.String")
            .ColumnName = "colA"
End With
With colB
            .DataType = System.Type.GetType("System.String")
            .ColumnName = "colB"
End With

我想将它添加到 colB 的 .expression 中,它将测试 colA 中的字符串值,如果为 True,则放置一个字符串值,如果为 False,则放置另一个字符串值。

像这样的一件事:

colB.Expression = IIF(colA="toto", "cool", "not cool")

但是我对语法有困难。每次表达式的求值都是False。

更新: 我试试这个和这个工作:

colB.Expression = "IIF([colA] = 'stringA', 'stringB', 'stringC')"

但是现在,如果我想测试一个空值,语法是什么?

测试是否为空:

colB.Expression = "IIF([colA] = '', 'stringB', 'stringC')"

要测试空值:

colB.Expression = "IIF([colA] IS NULL, 'stringB', 'stringC')"

要测试 null 或空:

colB.Expression = "IIF([colA] = '' or [colA] IS NULL, 'stringB', 'stringC')"