Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop rows of dataset in Reporting services rdl custom code

How can I loop through the rows of a dataset in the custom code?
I have a report containing a dataset. I pass the dataset as a parameter to the custom code function. But what then? Where is a reference about the available members etc.?
Here is my dummy sample code so far:

Public Function ShowParameterValues(ByVal ds as DataSet) as object()
    Dim codes() As Object
    Array.Resize(codes,dc.???.Count)
    codes(0)=ds??(field???)(row??)
    return codes
End Function

Please note: this will be a very simple script (if it'll work), so I don't want to go into custom assemblies etc.

like image 786
kcode Avatar asked Aug 31 '10 08:08

kcode


People also ask

What is difference between shared data source and shared dataset in SSRS?

A data source contains details about the database server you will be connecting to, the login to use and the database to use. A dataset contains the specific query that will be used to fetch data for a particular report. 1. In the Solution Explorer, right-click on Shared Data Sources and select Add New Data Source.

How to see the dataset in SSRS report?

In Design view, on the View menu, select Report Data, or use CTRL+ALT+D.

How do I add assembly reference in SSRS?

To add an assembly reference to a report In Design view, right-click the design surface outside the border of the report and click Report Properties. Click References. In Add or remove assemblies, click Add and then click the ellipsis button to browse to the assembly.


1 Answers

I think you got your answer at:

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a7d59224-0ee5-491e-883b-2e5fcb3edeab/iterate-through-rows-of-dataset-in-reports-custom-code?forum=sqlreportingservices

There were two important pieces of information I was able to grasp from the above link:

First, 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.

Second, There was a solution posted as to how one can Iterate through rows of dataset in report's custom code by "transforming" the data set into a multivalued parameter (or if several fields are needed, transforming it in multiple multivalued parameters):

The multivalued Report Parameter must have the following characteristics:

Hidden = True, Allow Multiple Values = True

Available Values tab: Choose the desired dataset. Select the searchable id as Value id, and the field you want to expose as Label Field.

Default Values Tab: Get Values from a Query. Choose the same Dataset as choosen in the available Values Tab. Value Field the same you choose for value id.

Set the parameter to never refresh (or it will be loading the data from each iteraction of another parameter).

Now, the idea is make this Parameter "searchable". From this point you exposed the Dataset as an array in the Multi valued Parameter.

Now in a custom code insert the following code:

function GetDataSetLabelFromValue( id as integer) as String
dim i as integer
i = 0
for i = 1 to Report.Parameters!YourParameter.Count()
if Report.Parameters!YourParameter.Value(i) = id then
    GetDataSetLabelFromValue = Report.YourParameter!ReportParameter1.Label(i)
    Exit For
End if
next i
End Function

Were you able to do what you wanted?

like image 105
Anjani Kumar Agrawal Avatar answered Sep 17 '22 18:09

Anjani Kumar Agrawal