【问题标题】:Remove Duplicate Function with LookupSet returing #Error in SSRS使用 LookupSet 在 SSRS 中返回 #Error 删除重复函数
【发布时间】:2017-03-29 17:47:54
【问题描述】:

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

function 代码是:

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 是,

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

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

当我从expression 中删除RemoveDuplicates 函数时,它适用于所有情况。我是否需要在vb function 中进行更改以合并空白?我在这里缺少什么?

【问题讨论】:

  • 您是否需要这些空白,或者您可以在运行代码之前删除它们吗?
  • 空白是指没有数据的列
  • 是的,我假设你的意思是 Fields!code.Value = nothing
  • 是的.. 完全正确。如果所有值都为空,则该函数将引发错误
  • 代码的预期输入是什么样的?

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


【解决方案1】:

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

将函数更改如下:(null/nothing 值将被转换为空字符串'')

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】:

    要处理空白字段,请更新您的共享函数代码,如下所示:

    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
    

    另外,更新文本框表达式以将空字符串删除为

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

    干杯,
    基尔蒂·辛格 |解决方案 IT 服务

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题,结果是由于 LookupSet 的输出与自定义函数不兼容。我在 LookupSet 函数的输出及其两个输入上使用 CStr() 解决了它。

      这解决了我的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-29
        • 1970-01-01
        相关资源
        最近更新 更多