none
Retrieve a Parameter from an RDLC Report

    Question

  • I am wondering if there is a way to get a parameter value from an RDLC report.  I have already given the parameter a default value in the RDLC report and I am wondering if there is a way to retrieve that value from the report.  I am using VS2010 and SQL 2008 R2.

    I want to use that value that I have already preset in the report for printing purposes.

    Thanks,

    Stacy

    Friday, April 05, 2013 3:17 PM

All replies

  • .GetReportParameters will give you parameter details like name and value.

    Check this article for more details. http://odetocode.com/articles/123.aspx


    Please Mark posts as answers or helpful so that others can more easily find the answers they seek.

    Friday, April 05, 2013 4:23 PM
  • I am programming in winforms vb.net not asp and Sql 2008 R2 and I have a local report.

    It seems in vb.net you can only use getreportparameters with the reportviewer.  Is that correct?

    Thanks,

    Stacy

    Friday, April 05, 2013 5:12 PM
  • Reportviewer can be used in winforms and web-based.

    You can make it hidden reportviewer too, if you want.

    Here is one example - http://www.codeproject.com/Articles/35684/The-WinForms-ReportViewer-and-Multiple-Report-Defi


    Please Mark posts as answers or helpful so that others can more easily find the answers they seek.


    • Edited by Sachi_SG Friday, April 05, 2013 5:37 PM example
    Friday, April 05, 2013 5:36 PM
  • Yes I have one reportviewer already setup that I use for all my reports.  This report, however, I am printing right to the printer.  It works great except when the report is landscape.

    How would I print the report programically when the reportviewer is hidden?  That might work because my landscape reports print properly if they are printed out of the reportviewer.  The user just doesn't want to view the report on the screen just send it directly to the printer.

    Thanks for your reply.

    Stacy

    Friday, April 05, 2013 6:40 PM
  •  The user just doesn't want to view the report on the screen just send it directly to the printer.

    Hello,

    Based on your description,  you want to programmatically print a report without viewing it. If so, you can try to using the LocalReport object and the CreateStreamCallback callback function. For the details, please refer to the following walkthrough: Printing a Local Report without Preview

    Regards,
    Fanny Liu

    If you have any feedback on our support, please click here.


    Fanny Liu
    TechNet Community Support

    Monday, April 08, 2013 2:35 AM
    Moderator
  • Thanks for your reply Fanny.  I do already have reports set up to print without the reportviewer - directly to the printer.  It is the code from the link you provided above.  It works great EXCEPT, when the report I am trying to print is Landscape!  

    My problem is when the user clicks the printer button it will print Work Orders which are Portrait and then for each work order there might be other reports that need to be printed also.  Those reports are usually (not always) landscape.  I have been racking my brain trying to think of a way to find out which report is printing and if it is landscape so I could run different code to change the pagewidth and pageheight on the export sub below

    Private Sub Export(ByVal report As LocalReport)
            Dim deviceInfo As String = "<DeviceInfo>" & _
                "<OutputFormat>EMF</OutputFormat>" & _
                "<PageWidth>8.5in</PageWidth>" & _
                "<PageHeight>11in</PageHeight>" & _
                "<MarginTop>0.25in</MarginTop>" & _
                "<MarginLeft>0.25in</MarginLeft>" & _
                "<MarginRight>0.25in</MarginRight>" & _
                "<MarginBottom>0.25in</MarginBottom>" & _
                "</DeviceInfo>"
            Dim warnings As Warning()
            m_streams = New List(Of Stream)()
            report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
            For Each stream As Stream In m_streams
                stream.Position = 0
            Next
        End Sub

    and add the PrintDoc.DefaultPageSettings.Landscape = True to the Print sub below.

      Private Sub Print()
            If m_streams Is Nothing OrElse m_streams.Count = 0 Then
                Throw New Exception("Error: no stream to print.")
            End If
            Dim printDoc As New PrintDocument()
            If Not printDoc.PrinterSettings.IsValid Then
                Throw New Exception("Error: cannot find the default printer.")
            Else
                AddHandler printDoc.PrintPage, AddressOf PrintPage
                m_currentPageIndex = 0
                'printDoc.DefaultPageSettings.Landscape = True
                printDoc.Print()
            End If
        End Sub

    So in order for the Landscape report to print properly directly to the printer those two changes would need to be made.  So that brings us to the retrieving the parameter from the report.  My thought was that I could set a parameter in each report like zPortrait and then make it either True or False depending if the report is Portrait or Landscape then I would know which subs to run with the right settings to print either landscape or portrait directly to the printer.

    I hope that makes sense.  I have been working on this for a week now and have tried so many different ways to make it work!  I have even tried exporting the reports to PDF's and then tried printing those directly to the printer (because it will export the PDF correctly as Portrait or Landscape because it exports from the reportviewer which I have hidden so the user doesn't really see it.)  But that opens up an Adobe Reader window when you go to print them and gives a write error if I try to print to many files in a row.   I can't believe it is this difficult to print directly to a printer and have it work for either landscape or portrait.

    Thanks for your help!

    Stacy



    • Edited by tnswalker Monday, April 08, 2013 4:46 PM
    Monday, April 08, 2013 4:43 PM
  • Hello,

    Not good at programming, but the following blog may help solve this issue. No need to pass the parameter, use the class to ReportUtils to specify the report orientation and set deciveInfo values based on the orientation values.

    Please refer to:http://www.codeproject.com/Articles/38554/Microsoft-Reporting-Services-Part-II#Printing

    Thanks.

    Tuesday, April 09, 2013 9:36 AM
  • Thanks summer_qin.  I had tried that code also, but I get an error: The input XML does not conform to the schema.  XML grammar is described in the API documentation.  For XML in reports, refer to Report Definition Language syntax.  I'm pretty new to vb.net and haven't a clue what it means. 

    My report is an rdlc file and it is setup for landscape.  It is a local report and is also attached to a datasource.  I'm thinking the error is referring to the datasource possibly.  In your link above there is a spot where it says to

    Define report DataSource, Parameters, etc

    and I added in  rpt.DataSources.Add(New ReportDataSource("DataSet1")) which is my datasource for this report.

    Thanks for your help!

    Stacy

    Tuesday, April 09, 2013 3:38 PM