Passing parameter to crystal report with VS 2005 using C#

Last post 03-12-2007 6:54 PM by Marian Kostal. 1 replies.

Sort Posts:

  • Crying [:'(] Passing parameter to crystal report with VS 2005 using C#

    03-11-2007, 11:15 AM
    • Loading...
    • kieboy
    • Joined on 09-06-2004, 4:47 AM
    • Philippines/Saudi Arabia
    • Posts 119
    Hi peeps, after hours of searching here, I still cant find the solution on how to pass a parameter to the sql query for the report. I read some examples about this but all are done in VB script can u guys help me with C#? With just using the wizard, I can easily do this but of course, the same report is always displayed because of the formula. I need to be able to pass a different value coming from a session lets say Session["formNo"].ToString()

    I know how to add a parameter (having read from the other posts here) to the report thus the formula of my report looks like this: {ASP_MainForm.FormNo} = {?formNo} (where the {?formNo} should be the value from the Session["formNo"].ToString())

     Now in my aspx page this is all i have:

    <cr:crystalreportviewer id="CrystalReportViewer1" runat="server" autodatabind="True" Height="1039px" ReportSourceID="CrystalReportSource1"

    Width="901px"></cr:crystalreportviewer>
            <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
                <Report FileName="CrystalReport1.rpt">
                </Report>
            </CR:CrystalReportSource>

    what else do i need to code in to make this work? I even saw from one of the posts here with a code inserted like this

    <Report FileName="SS_Server.rpt">
                    <Parameters>
                        <CR:Parameter ConvertEmptyStringToNull="False" DefaultValue="45"
                            Name="SERVER_ID" ReportName="" />
                    </Parameters>
                </Report>

    so in my case Id make it

    <Report FileName="CrystalReport1.rpt">
                    <Parameters>
                        <CR:Parameter ConvertEmptyStringToNull="False" DefaultValue="45" (? not sure of this)
                            Name="formNo" ReportName="" />
                    </Parameters>
                </Report>


    what about the code behind page? There are lots of codes in the examples done in VB script but have no idea what it does,
    plus if you guys can help me about the removing of the password prompt everytime I open the page done in C# it would be a great help too. Thanks all.

     
    Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Passing parameter to crystal report with VS 2005 using C#

    03-12-2007, 6:54 PM
    Answer
    • Loading...
    • Marian Kostal
    • Joined on 01-10-2007, 6:33 PM
    • Banovce nad Bebravou, Slovakia
    • Posts 190

    If your .aspx page contains code like this:


        Height="1039px" ReportSourceID="CrystalReportSource1" Width="901px" />
    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        <Report FileName="CrystalReport1.rpt">
        </Report>
    </CR:CrystalReportSource>

    You can set parameter in codehind this way:

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.CrystalReportSource1.Report.Parameters.Add(...);
        }
    }

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter