检查自定义代码函数中的NULL日期

时间:2012-02-07 22:09:28

标签: vb.net reporting-services sql-server-2008-r2

我正在尝试为我的SSRS报告实现一个函数,该函数将根据三个日期的值返回颜色值:

Function SetBoxColor(dateOne As Date, dateTwo As Date, dateThree As Date) As String
' Determine colors for text box
  If (dateOne Is Nothing) Then
    SetBoxColor = "Blue"
  Else
    If (dateThree Is Nothing) Then
      If dateOne >= Date.Now Then
        If DateDiff("d",dateOne,Date.Now) < 90
          SetBoxColor = "Yellow"
        Else
          SetBoxColor = "White"
        End If
      Else
        SetBoxColor = "Orange"
      End If
    Else
      If dateThree <= dateOne Or (Month(dateThree) = Month(dateOne) And Year(dateThree) = Year(dateOne)) Then
        SetBoxColor = "Green"
      Else
        SetBoxColor = "Red"
      End If
    End If
  End If
  Return SetBoxColor
End Function

传递给此函数的参数是来自我的数据集的可空日期(SQL Server日期类型),我从TextBox的BackgroundColor属性调用该函数:

=Code.SetBoxColor(Fields!dateOne.Value, Fields!dateTwo.Value, Fields!dateThree.Value)

按原样运行该函数将返回错误:

  

'Is'需要具有引用类型的操作数,但此操作数的值类型为“Date”。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:9)

您是否尝试过dateOne = Nothing