Pergunta

I'm required to do validation for an SSRS report and hope that someone can help me out on this.

I'm trying to take a time string in the form of "h:mm" and parse it to time.

If the parsing is ok, run the report, if the parsing fails, I want to display a friendly error message on the report instead of getting "Local Report Execution Failed".

Thanks in advance for the help!

Foi útil?

Solução

You can create two custom functions in your SSRS report like following.

'Parse the string and return a DateTime object representing the time
Public Function ParseTime(fTime As String) As DateTime
    Dim dtTime As dateTime = Nothing
    DateTime.TryParse(fTime, dtTime)
    Return dtTime
End Function

'Return error message if the parsing fails, otherwise return empty string
Public Function ParsingError(fTime As String) As String
    Dim dtTime As dateTime = Nothing
    If Not DateTime.TryParse(fTime, dtTime) then
        Return "Error converting time"
    Else
        Return ""
    End If
End Function

Then you can use those functions in the expression of the corresponding textboxes like this:

=Code.ParseTime(Parameters!TimeString.Value)

and

=Code.ParsingError(Parameters!TimeString.Value)

Hope it helps.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top