问题
In my SSRS
Report, I am using LOOKUPSET
function to concatenate
one of the field values
. In-order to get distinct concatenated
values I used RemoveDuplicates
Vb Function in Report Code.
the function
code is:
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
My TextBox Expression
is,
=Join(Code.RemoveDuplicates(LookUpSet(Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1")), " , ")
This expression
works fine in all the cases except blanks
.If Fields!code.Value
contain only blanks, Report Preview Returns the error #Error
in the field value
.
When I removed the RemoveDuplicates
function from the expression
, it works fine for all the cases. Do I need to make changes in the vb function
to incorporate blanks also? what I am missing here?
回答1:
To solve the problem, make following changes to your code:
change the function as following: (null/nothing values will be then converted to empty string '')
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
For j As Integer = 0 To items.Length - 1
If j > 0 Then
Continue For
End If
if(items(j) is nothing) then
items(j) = ""
End If
Next
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
modify expression to remove empty string :
=Replace(
Join(Code.RemoveDuplicates(
LookUpSet(Fields!id.Value, Fields!id.Value, Fields!code.Value,"ds_DataSet1")
), " , ")
, ", ,", "")
来源:https://stackoverflow.com/questions/43100631/remove-duplicate-function-with-lookupset-returing-error-in-ssrs