How to pass parameters to the report

Suppose we want the title of the report to be dynamic. We have the desired title in a session variable. How do we pass this value to a text field in the report's title band using VB? I don't seem to find a discussion of this in the manual.

Thanks

Comments

  • edited 6:52AM
    Hello,

    This is in the programmer's manual:
    wrote:
    The report may have parameters. Read more about this in the User's Manual. To pass a value to the parameter, use the SetParameterValue method of the Report object:

    report1.Load("report.frx");
    report1.SetParameterValue("MyParam", 10);
    report1.Show();

    This method is declared as follows:

    public void SetParameterValue(string complexName, object value)

    Specify the parameter's name in the complexName parameter. To access a nested parameter, use its full name, for example:

    "ParentParameter.ChildParameter"
  • edited 6:52AM
    AlexTZ wrote: »
    Hello,

    This is in the programmer's manual:
    AlexTZ wrote: »
    The report may have parameters. Read more about this in the User's Manual. To pass a value to the parameter, use the SetParameterValue method of the Report object:

    report1.Load("report.frx");
    report1.SetParameterValue("MyParam", 10);
    report1.Show();

    This method is declared as follows:

    public void SetParameterValue(string complexName, object value)

    Specify the parameter's name in the complexName parameter. To access a nested parameter, use its full name, for example:

    "ParentParameter.ChildParameter"
    Thanks Alex, I was looking in the Users Guide and didn't find it. Unfortunately your instructions are too brief for a beginner like me. First question is "Where do these code lines go? In the webpage or somewhere in the report?" Second question is what do they look like in VB? " My code converter chokes on the public void line. And my attempt to put it in the page like this

    <script language="vb" runat="server">
    Protected Sub WebReport1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebReport1.Load
    WebReport1.Load("testreportinside.frx")
    WebReport1.SetParameterValue("ListName", "My Committee")
    End Sub
    </script>
    produces syntax errors.
  • edited 6:52AM
    For asp.net, the method is little different:

    "To use this method in ASP.NET, you need to create the event handler for the StartReport event of the WebReport component. The report can be accessed through the WebReport.Report property:

    webReport1.Report.SetParameterValue("MyParam", 10);
    "
  • pinbotpinbot Texas
    edited 6:52AM

    Are you putting this in your Code Behind file (page.aspx.vb)?


    I code in c# but maybe this would help you get started. Should be fairly easy to convert to VB.

    In C#, to set the parameter to a session variable, you'd do something like:
    Rpt.SetParameterValue("ParamName", Session["SessionVariable"].ToString());

    In your report band, set the contents of the textobject to be "[ParameterName]".


    I have a report that I pass several parameters to and export to pdf and then return to the browser. I'm not using the WebReport viewer, just FastReports directly. If you are trying to do the same, here is my Page_Load function (from default.aspx.cs) which works well.

    protected void Page_Load(object sender, EventArgs e)
    {
    int Id=0,Batch=0;
    string IdText="",Hash="";


    IdText = Request.QueryString["InvoiceNumber"];
    Hash = Request.QueryString["Security"];

    if (string.IsNullOrEmpty(IdText)==false)
    if (int.TryParse(IdText,out Id)==false) Id=0;
    if (string.IsNullOrEmpty(Hash)) Hash="";
    if (Hash.IndexOf(' ')>0) Hash = "";

    // **** THIS IS IMPORTANT TO MAKE WORK on A WEB SERVER. FR WILL THROW A .NET ERROR LOOKING FOR A CONFIG FILE IF YOU DON'T SET THIS 'TRUE'
    FastReport.Utils.Config.WebMode=true;


    if (Id != 0 && Hash != "")
    { SqlConnection oSQLConn = new SqlConnection();
    oSQLConn.ConnectionString = "XXXXXXX";
    string queryString = "select invoicenumber,invoicehash from alnonlineinvoices where InvoiceNumber="+Id.ToString();
    queryString+=" and invoicehash='"+Hash+"'";
    SqlCommand command = new SqlCommand(queryString, oSQLConn);
    oSQLConn.Open();

    SqlDataReader reader = command.ExecuteReader();
    int count = 0;
    if (!reader.Read()) Id=0;

    FastReport.Report Rpt = new FastReport.Report();
    Rpt.Load(Server.MapPath("./App_Data/ALNInvoices.Frx"));
    Rpt.SetParameterValue("InvoiceBatch", 0);
    Rpt.SetParameterValue("InvoiceNumber", Id);
    Rpt.SetParameterValue("SendAll", "Y");
    Rpt.SetParameterValue("AccountToPrint", "");
    Rpt.SetParameterValue("PrintOrEMail", "A");

    Rpt.Prepare();
    FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
    export.PrintOptimized = false;
    export.OpenAfterExport = false;


    System.IO.MemoryStream s = new System.IO.MemoryStream();
    Rpt.Export(export, s);
    s.Position = 0;

    Response.ClearHeaders();
    Response.Clear();
    Response.Cache.SetMaxAge(new TimeSpan(0));
    Response.Cache.SetExpires(new DateTime(0));
    Response.Cache.SetNoServerCaching();

    Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;
    Response.AppendHeader("Content-Disposition", "inline;filename=\"Invoice" + Id.ToString() + "\"");
    Byte[] buffer = new Byte[s.Length];
    s.Read(buffer, 0, (int)s.Length);
    Response.BinaryWrite(buffer);
    Response.Flush();
    Response.End();
    }

    }
  • edited 6:52AM

    Thanks pin. I guess that helps somewhat. As near as I can tell the SetParameterValue needs to be executed sometime after the report is loaded. I have placed it in the page.prerender.complete event like this.

    Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
    WebReport1.Report.SetParameterValue("ListName", "My Committee")
    End Sub

    In my case I have the report object on the page so I don't have to do a lot of the manual loading etc that you have.
    In the report designer I created a parameter named ListName and added a text label to the page header. The text value of the label is
    [ListName]. This all seems to run OK but the result is that the text label is blank.
  • edited 6:52AM
    dfreeman wrote: »
    Thanks pin. I guess that helps somewhat. As near as I can tell the SetParameterValue needs to be executed sometime after the report is loaded. I have placed it in the page.prerender.complete event like this.

    Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
    WebReport1.Report.SetParameterValue("ListName", "My Committee")
    End Sub

    In my case I have the report object on the page so I don't have to do a lot of the manual loading etc that you have.
    In the report designer I created a parameter named ListName and added a text label to the page header. The text value of the label is
    [ListName]. This all seems to run OK but the result is that the text label is blank.
    For anyone interested in this topic, the light bulb finally came on and I solved the problem with this.

    Protected Sub WebReport1_StartReport(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebReport1.StartReport
    WebReport1.Report.SetParameterValue("ListName", Session("CommitteeName"))
    End Sub

    Thanks to all.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.