Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding reporting services parameters from code behind 1

Status
Not open for further replies.

tomouse

Technical User
Aug 30, 2010
50
I am sending data from my ASP.NET website to a local Reporting Services report (rdlc), which is sitting in a ReportViewer control. It is mostly running fine, with one exception. I am not able to display the parameters that the user is sending to the report. Here is the code on the aspx file:
Code:
       <asp:Panel runat="server" ID="pnlReport" Width="90%" Height="850px" >
            <asp:ObjectDataSource ID="ods1" runat="server"  SelectMethod="PurchaseConsultarPorIDPurchase" TypeName="DEApp.dtsDEAppTableAdapters.tbaConsultarPurchases" >
                <SelectParameters><asp:Parameter Name="idPurchase" Type="Int32" /></SelectParameters>
            </asp:ObjectDataSource>      
                    
            <rsweb:ReportViewer ID="rptv1" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="650px" Width="80%" >
                <LocalReport ReportPath="rptPurchase.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="ods1" Name="dtsDEApp_dttPurchaseConsultarView" />
                    </DataSources>
                </LocalReport>
            </rsweb:ReportViewer>
        </asp:Panel>
And here is the codebehind:
Code:
        Dim rpt As New LocalReport
        rpt.ReportPath = "rptPurchase.rdlc"

        ods1.SelectMethod = "PurchaseConsultarPorIDPurchase"
        ods1.SelectParameters("idPurchase").DefaultValue = id
'*****
        Dim prmIdPurchase As New Microsoft.Reporting.WebForms.ReportParameter("idPurchase", id)
        Dim prmLang As New Microsoft.Reporting.WebForms.ReportParameter("iLang", iLangArg)
        Dim pcol As New List(Of ReportParameter)
        pcol.Add(prmIdPurchase)
        pcol.Add(prmLang)
        rpt.SetParameters(pcol)
'*****
        rptv1.LocalReport.Refresh()
On the actual report I have added a textbox and given it the expression: =Parameters!idPurchase.Value. However, even though this should display as 171, it is actually showing as 0.

In the block above I have put **stars** round the section where I add the report parameters. Seems that although the SelectParameters (above) for the datasources are going across fine (I know this because the correct data is showing in the report), the Report parameters aren't. Can anyone see what I'm doing wrong?
 
Just wondering if maybe the issue is related to *when* I add the parameters? Because if I mispell the parameter names an error occurs (normally there is no error). But the value of the parameters when displayed on the report always shows as the default value. COuld the answer be to somehow set the parameters earlier in the process?
 
since you are using a data source control to populate the report, why not set the select parameter to pull the value from the appropiate place (query string, control, etc).

I think you can do that with data source controls. if not I would drop the data source control altogether and wire up the data with actual code.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Yeah, good thinking. I got a little obsessed with why the report parameters weren't coming through (they should be showing up!!!), but whatever the reason, I've ended up putting the extra info I needed into the dataset as you suggest. Still no idea why the report parameters aren't working, but this fixes my problem. Thanks for the suggestion,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top