Link to home
Start Free TrialLog in
Avatar of EYoung
EYoungFlag for United States of America

asked on

How pass parm from VB webform to ssrs report

Can someone show me how to pass a parameter from a VB (vs 2010) web form to an SSRS report?

Here is the vb code on the web form (code behind) but it is generating an error:

Imports Microsoft.Reporting.WebForms

Partial Class rptStoresFlashSummary
    Inherits System.Web.UI.Page

    Protected Sub form1_Load(sender As Object, e As System.EventArgs) Handles form1.Load
        Dim mParm(0) As Microsoft.Reporting.WebForms.ReportParameter
        mParm(0) = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", Session("mSales_Date_Parm"))
        StoresFlashSummary.LocalReport.SetParameters(mParm(0))
    End Sub
End Class



The above code generates the following error on the line "mParm(0) = New...":

"Overload resolution failed because no accessible 'New' can be called without a narrowing conversion..."

Any suggestions on how to pass a parm in VB web form to an SSRS report would be appreciated.

Thank you
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Hi, please try with:
mParm(0) = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", CType(Session("mSales_Date_Parm"), String))

Open in new window

Avatar of Alpesh Patel
LocalReport myReport = new LocalReport();
myReport.ReportPath = Server.MapPath("~/Path/To/Report.rdlc");

ReportParameter myParam = new ReportParameter("ParamName", "ParamValue");
myReport.SetParameters(new ReportParameter[] { myParam });
Avatar of EYoung

ASKER

yv989c:

I think your suggestion might work but when I try it, the report does not display.  Instead, the report looks like it is getting ready to display and has the grey square in the middle with the word "Loading" and the green circle to its left.  This grey square just flashes on and off and the report never displays the data.

When I commend out the three lines in the Page_Load procedure, the report displays correctly but does not show the passed parameter.

The Page_Load section in the VB code behind form is shown below along with the aspx code.

Thanks for any help.
Here is the code from the VB code behind procedure for the report:

Imports Microsoft.Reporting.WebForms

Partial Class rptStoresFlashSummary
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim mParm(0) As Microsoft.Reporting.WebForms.ReportParameter
        mParm(0) = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", CType(Session("mSales_Date_Parm"), String))
        StoresFlashSummary.LocalReport.SetParameters(mParm(0))
    End Sub
End Class



Here is the code from the report's aspx form:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="rptStoresFlashSummary.aspx.vb" Inherits="rptStoresFlashSummary" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <rsweb:ReportViewer ID="StoresFlashSummary" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
            ShowCredentialPrompts="False" ShowParameterPrompts="False" Width="1000px" 
            Height="859px">
            <LocalReport ReportPath="Stores_Flash_Summary.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" 
                        Name="Retail_Flash_Detail_DataSet" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>

        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetData" 
            TypeName="Retail_Flash_Detail_DataSetTableAdapters.Retail_Flash_DetailTableAdapter">
        </asp:ObjectDataSource>

    </div>
    </form>
</body>
</html>

Open in new window

Avatar of EYoung

ASKER

PatelAlpesh:

My code is VB not C.  Can you show me your suggestion using VB?

Thanks
Hi, try this:
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim mParm(0) As Microsoft.Reporting.WebForms.ReportParameter
        mParm(0) = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", CType(Session("mSales_Date_Parm"), String))
        StoresFlashSummary.LocalReport.SetParameters(mParm(0))
        StoresFlashSummary.DataBind()
    End Sub

Open in new window


Call the DataBind method like the code above.
Or maybe?
ObjectDataSource1.DataBind()

Open in new window

Avatar of EYoung

ASKER

Not sure what you mean by "Call the DataBind method like the code above" so I just copied your suggestion into my program and used it instead of mine.  The report still is flashing the "Loading..." message over and over and never shows the report data.  See attached screen image.  Thank you for sticking with me on this.

Is there some type of conflict between the code behind and the aspx code?
Report-screen-image.JPG
Avatar of EYoung

ASKER

Here is a better screen shot...
Report-screen-image.JPG
Avatar of EYoung

ASKER

Here is what I have now in my VB code behind form:

Imports Microsoft.Reporting.WebForms

Partial Class rptStoresFlashSummary
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim mParm(0) As Microsoft.Reporting.WebForms.ReportParameter
        mParm(0) = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", CType(Session("mSales_Date_Parm"), String))
        StoresFlashSummary.LocalReport.SetParameters(mParm(0))
        StoresFlashSummary.DataBind()
    End Sub
End Class
Avatar of EYoung

ASKER

Here is a question about this phrase:  "CType(Session("mSales_Date_Parm"), String))"

The variable mSales_Date_Parm is already a "string" variable so could it be causing a problem trying to convert it to a string?
Avatar of EYoung

ASKER

When I comment out all of the lines in the Page_Load section, the report runs correctly and shows the data, just not the passed parameter.  Then when I un-comment out the Page_Load lines, the report does not show and just flashes the "Loading..." box over and over like it is trying to prepare the report.

I think there may be a conflict between the VB code behind in the Page_Load section and the aspx code.

Maybe I am not not calling the report correctly when trying to pass a parameter?

Any ideas or suggestions?
Hi, try this instead:
Imports Microsoft.Reporting.WebForms

Partial Class rptStoresFlashSummary
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim mParm(0) As Microsoft.Reporting.WebForms.ReportParameter
        mParm(0) = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", CType(Session("mSales_Date_Parm"), String))
        StoresFlashSummary.LocalReport.SetParameters(mParm(0))
        ObjectDataSource1.DataBind()
    End Sub
End Class

Open in new window

If this dont work I will find more info about the ReportViewer class because Im not familiar with this.
Avatar of EYoung

ASKER

Same results.  The report just flashes the "Loading..." box over and over.

I think it may be a conflict between the above vb code behind and the aspx code.  In other words, I don't think I am calling the report correctly when trying to pass a parameter.  I suspect that I should be only calling the report from the vb code behind as shown in the Page_Load section or only calling it from the aspx page, but not both.

Below is the aspx code.  Thanks for sticking with me on this.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="rptStoresFlashSummary.aspx.vb" Inherits="rptStoresFlashSummary" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <rsweb:ReportViewer ID="StoresFlashSummary" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
            ShowCredentialPrompts="False" ShowParameterPrompts="False" Width="1000px" 
            Height="859px">
            <LocalReport ReportPath="Stores_Flash_Summary.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" 
                        Name="Retail_Flash_Detail_DataSet" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>

        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetData" 
            TypeName="Retail_Flash_Detail_DataSetTableAdapters.Retail_Flash_DetailTableAdapter">
        </asp:ObjectDataSource>

    </div>
    </form>
</body>
</html>

Open in new window

Hi!
Update your code with this:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim mParmSales_Date_Parm As Microsoft.Reporting.WebForms.ReportParameter
            mParmSales_Date_Parm  = New Microsoft.Reporting.WebForms.ReportParameter("Sales_Date_Parm", CType(Session("mSales_Date_Parm"), String))
            StoresFlashSummary.LocalReport.SetParameters(mParmSales_Date_Parm)
            StoresFlashSummary.DataBind()
        End If
    End Sub

Open in new window

I had not seen that you are using a script manager, so you need to init your report data just once, now the code is controlling that (If Not IsPostBack Then....).
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EYoung

ASKER

Yes, that fixed it.  Everything works perfectly now.  Thank you so much for the answer and for sticking with me on this.

I guess the reason why the report kept flashing was because it was caught in a postback loop?

At any rate, the report is displaying correctly and the passed parameter is showing up on the report.
Good to know! And yes it was a postback loop hehe