SSRS hate me. Right now, the feeling is mutual.
I'm attempting to work with strings that may or may not be null. I was using VB's IIF
statement; after doing some searching on the errors I was receiving, I discovered that the IIF
statement doesn't short-circuit the way you'd expect most if statements to do. I fixed the issue by changing the IIF
statements to If
. Thought things were good.
Until I ran into the problem referenced here.
So I'm stuck. I've attempted to place everything in a report code block, thinking that I could isolate myself from the problems I'm running into, like so:
Public Function DisplayUserName(ByVal UserName As String, ByVal FirstName As String, ByVal MiddleName As String, ByVal LastName As String) As String
'SSRS sucks. Specifically, with empty strings and if statements that aren't IIF. Hence the code block.
'See https://stackoverflow.com/q/27418185/677526. Unfortunately IIF can't work here.
Dim result As New System.Text.StringBuilder()
If Not System.String.IsNullOrWhitespace(UserName) Then
result.Append(UserName)
result.Append(VbCrLf)
End If
If Not System.String.IsNullOrWhitespace(FirstName) Then
result.Append(FirstName)
result.Append(" ")
End If
If Not System.String.IsNullOrWhitespace(MiddleName) Then
result.Append(GetChar(MiddleName, 1))
result.Append(". ")
End If
If Not System.String.IsNullOrWhitespace(LastName) Then
result.Append(LastName)
End If
Return result.ToString()
End Function
...but now I'm running into issues with IsNullOrWhitespace
not being a member of System.String
.
I'm almost at a loss here, as I'm fighting my tools. Has anyone run into this before when trying to concatenate a group of strings that can be null? How did you solve the issue? Of note, I can do this in our SQL query (and I'm almost about to give up and say whatever) but string concatenation seems to slow the query down somewhat.