Iterate through rows of dataset in report's custom code
Hello, How can I iterate 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 As the task I want to accomplish is very simple, I want to keep it in the custom code instead of writing any custom assemblies etc. Thank you!
August 31st, 2010 1:07pm

Datasets have Tables and Tables have DataRows, which have DataColumns. Assuming that you have only one result set, you can iterate over ds.Tables(0).DataRows with something like this (in C#, but you can translate to vb): DataSet ds = new DataSet(); foreach (DataRow row in ds.Tables[0].Rows) { foreach (object column in row.ItemArray) { Console.WriteLine(column.ToString()); } }
Free Windows Admin Tool Kit Click here and download it now
August 31st, 2010 4:36pm

Hi , I dont think we can pass entire dataset to custom code rather than field[s] . But you can have a calulated field[s] which might differ from the original dataset fields . Thanks .Rajkumar Yelugu
September 1st, 2010 8:49am

Justin, 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. Uwe, The only way to effectively loop through the rows of a report dataset is to call a custom function or referenced method in a report data region expression. Using this technique, it may be possible to pass all of the the row and field information into a code structure, array or collection. Honestly though, if you need to have this level of control, you may be better off developing a web form rather than a report. The goal of SSRS is to simplify the reporting process rather than providing a deeply extensible programming environment. To use Reporting Services effectively, you need to think like a report designer, working with the product as it's designed, and not think like a programmer.Paul Turley, MVP [Hitachi Consulting] SQLServerBIBlog.com
Free Windows Admin Tool Kit Click here and download it now
September 1st, 2010 11:27am

Paul, thank you for your answer. Is there any class reference on the SSRS classes? I did not find anything about that, to at least know whats possible. Regards Uwe
September 3rd, 2010 2:43pm

The best thing you’ll find are in the more advanced books. Our Wrox Press book has a class references and sample code. Also, check Teo Lachev Bill Vaugh’s books as they focuse on programming extensions. Teo also maintains a good blog at prologika.com and I have linkes to other resources on my blog: sqlserverbiblog.com.Paul Turley, MVP [Hitachi Consulting] SQLServerBIBlog.com
Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2010 7:58pm

Actually, I've just found a way to do this without using external classes. I know this is an old thread but it might help for historical... Heres how, the ideal is to "transform" the data set into a multivalued parameter (or if you need several fields, transform it in multiple multivalued parameters). The multivalued Report Parameter must have the following characteristics: Hidden = True Allow Multiple Values = True Available Values tab: Chose 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 Hope it helps. Miguel Catalão
October 26th, 2010 9:05am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics