News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

List parameters from an SSRS (SQL Server Reporting Services) report

Started by dhilipkumar, Mar 27, 2009, 03:47 PM

Previous topic - Next topic

dhilipkumar

List parameters from an SSRS (SQL Server Reporting Services) report into an expression.I found some tips for doing this on James Kovacs' Weblog. But the code wasnt there, so here it is if you wish to implement it. Another useful msdn article is here.

I am using the imported DLL mechanism of writing code for reports (rather than the inline Code section) Simply add this method to an assembly and reference it in your report. Remember to copy the dll to "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\" to test it when previewing from Visual Studio.

To call this function put a TextBox on your report, edit the expression and add the line
=YourDll.DisplayParams(Parameters, "Param1, Param2");


The function for the assembly
using Microsoft.ReportingServices.ReportProcessing.ReportObjectModel;

///
/// Builds a list of SQL Server Reporting Services Parameters based on a parameter object
/// and a comma delimited string of param names
///
public static string DisplayParams(Parameters obj, string strParams)
{
    StringBuilder sbRet = new StringBuilder();
    try
    {
        //parameters in comma delimited list which matches
        //the name of the parameter in the collection.
        foreach (string sParam in strParams.Split(','))
        {
            //the name of the parameter
            sbRet.Append(String.Format("{0}: ", sParam));

            //concat parmaeter values
            if (obj[sParam].IsMultiValue)
                for (int i = 0; i < obj[sParam].Count - 1; i++)
                    sbRet.Append(String.Format("{0} : ",
                            ((string[])obj[sParam].Label)).Trim());
            else
                sbRet.Append(String.Format("{0}", obj[sParam].Label).Trim());

            //remove any trailing commas
            if (sbRet.ToString().EndsWith(", "))
                sbRet.Remove(sbRet.Length - 2, 2);

                        // seperator for each parameter
                        sbRet.Append("; ");
        }
    }
    catch (Exception)
    {
        return "Error building parameter list";
    }

    return sbRet.ToString();
}

osix