SSRS 通过Customer Code访问Dataset

A dataset in Reporting Services is not the same type of object as an ADO.Net dataset.  A report dataset is an internal object managed by the SSRS runtime (it's actually derived from a DataReader object) and not an XML structure containing datatables, etc. and cannot be passed into the report's custom code.

我们在SSRS中创建了DataSet,然后试图通过Customer Code来访问该DataSet。在一番查询之后,发现似乎没有办法直接在Customer Code中调用DataSet...

然而,Customer Code是可以访问Parameter的,而Parameter又和DataSet能够关联,于是就有了如下的方案来实现Customer Code 遍历DataSet。

1,创建DataSet,命名为Test_DataSet

创建测试用例,该DataSet有2列,分别为Id和Name

Select 1 As 'Id',1000 As 'Name' Union All
Select 2 As 'Id',2000 As 'Name'

2,创建Parameter,命名为Test_Parameter

在General页签,选择Data Type为Text,Allow multiple values为True,Hidden为True

在Availabe Values页签,选择Get values from a query,DataSet选择Test_DataSet,Value Filed选择Id,Label Field选择Name

在Default Values页签,选择Get vaules from a query,DataSet选择Test_DateSet,Value Field选择Id

在Advanced页签,选择Never refresh

3,选中Report,查看属性,在Code中输入如下Vb Code

这实现了根据输入的Id,遍历DataSet得到对应的Name的效果

 

Public Function GetValue(Id As Integer) As String
    Dim i As Integer
    i=0
    For i = 0 to Report.Parameters!Test_Parameter.Count() - 1
        If Report.Parameters!Test_Parameter.Value(i) = Id Then
            GetValue = Report.Parameters!Test_Parameter.Label(i) 
            Exit For
        End If
    Next i
End Function

 

4,在Report中,对应的单元格中,使用如下Expression进行调用

=Code.VerValue(1)

Preview Report,该单元格中显示值1000

 

转载于:https://www.cnblogs.com/Niko12230/p/5794968.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值