使用LookupSet删除重复功能在SSRS中撤消#Error

时间:2017-03-29 17:47:55

标签: sql-server vb.net reporting-services ssrs-2012

在我的SSRS报告中,我使用LOOKUPSET函数concatenate field values之一distinct concatenated。为了获得RemoveDuplicates值,我在报告代码中使用了function Vb函数。

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 代码为:

Expression

我的TextBox =Join(Code.RemoveDuplicates(LookUpSet(Fields!id.Value, Fields!id.Value, Fields!code.Value, "ds_DataSet1")), " , ") 是,

expression

blanks在除Fields!code.Value之外的所有情况下均可正常工作。如果#Error仅包含空格,则报告预览返回field value中的错误RemoveDuplicates

当我从expression中移除vb function函数时,它适用于所有情况。我是否需要在public class MyClass { public void swap(int x, int y){ int temp = x; x = y; y = temp; } } int w = 10, z = 20; MyClass m = new MyClass(); m.swap(w,z); System.out.println(w + " " + z); 中进行更改以包含空白?我在这里失踪了什么?

3 个答案:

答案 0 :(得分:1)

要处理空白字段,请如下更新您的共享功能代码:

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) <> "" 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

此外,更新Textbox表达式以将空字符串删除为

=IIF(IsNothing(Code.RemoveDuplicates(LookupSet(
    Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1"))(0)), "", 
Join(Code.RemoveDuplicates(LookUpSet(
Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1")), " , "))

干杯,
Kirti Singh | Soluzione IT服务

答案 1 :(得分:0)

要解决此问题,请对您的代码进行以下更改:

按如下所示更改功能:(空/零值将被转换为空字符串“”)

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

修改表达式以删除空字符串:

=Replace(
 Join(Code.RemoveDuplicates(
 LookUpSet(Fields!id.Value, Fields!id.Value, Fields!code.Value,"ds_DataSet1")
 ), " , ")
 , ",  ,", "")

答案 2 :(得分:0)

我有类似的问题,原来是由于LookupSet的输出和自定义函数之间的不兼容。我在LookupSet函数的输出及其两个输入上使用CStr()解决了这个问题。

这解决了我的问题。