Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi sir and ma'am. good day.. I have this asp.net website that generate records of Staff. As you type staff's Id no. in a texbox and click the 'Generate record' button, the page will be redirect to the another page of which the report has to be viewed.

In my first aspx.cs (session.aspx):

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class session : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["compNo"] = TextBox1.Text;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("Default.aspx");

    }
}



and in my second page.aspx (Default.aspx):


C#
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.Shared;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {


        Label1.Text = Session["compNo"].ToString();

       
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;

        ConnectionInfo con = new ConnectionInfo();
        con.ServerName = "myservername";
        con.DatabaseName = "My_database";



        CrystalReportViewer1.ParameterFieldInfo.Clear();
        CrystalReportViewer1.ReportSource = Server.MapPath("report.rpt");
        ParameterFields parameter = CrystalReportViewer1.ParameterFieldInfo;
        ParameterField staffno = new ParameterField();
        staffno.Name = "par_staffno";
        ParameterDiscreteValue par_staffno_value = new ParameterDiscreteValue();
        par_staffno_value.Value = Label1.Text;
        staffno.CurrentValues.Add(par_staffno_value);
        parameter.Add(staffno);

        foreach (TableLogOnInfo tlf in CrystalReportViewer1.LogOnInfo)
        {
            tlf.ConnectionInfo = con;
        }

    }
}



I have my report.rpt which I have already populated with designated fields like:

Staff_No, First_Name, Middle_Name, Last_Name

Also, I have already drag the CrystalReport Viewer from toolbox in my second page.

That's all what I have done. Any thing that I forgot to do, I do not know yet.


I got no errors. But when I run it in the browser, the report does not displayed in the browser and I got this "The parameter is incorrect" text at the end of my browser.


-- I'm using SQL server for my database, Visual Studio 2008 (C#) for the codes and everything..

What I have done wrong sir and ma'am? :)
Posted
Updated 3-Nov-10 0:39am
v2
Comments
Dalek Dave 3-Nov-10 6:40am    
Edited for Code Blocks

1 solution

Hello ninj23,

The ReportDocument contains a method ReportDocument.SetParameterValue[^] which you can use to set your parameters. Something like this;

// Assuming you have a CrystalReportViewer named CRViewer
protected void Button1_Click(object sender, EventArgs e)    
{
        Panel1.Visible = true;

        ConnectionInfo con = new ConnectionInfo();
        con.ServerName = "myservername";
        con.DatabaseName = "My_database";

        ReportDocument rpt = new ReportDocument();
        rpt.Load(Server.MapPath("report.rpt"));

        // rpt.SetParameter([0 based index of parameter], [value]);
        rpt.SetParameter(0, Session["compNo"].ToString());
	
	CRViewer.ReportSource = rpt

        foreach (TableLogOnInfo tlf in CrystalReportViewer1.LogOnInfo)
        {
            tlf.ConnectionInfo = con;
        }
}


Please keep in mind that this code was written directly into the browser so dont be shocked if it doesnt compile.

Little bit of extra reading for you;
 
Share this answer
 
Comments
ninj23 4-Nov-10 7:55am    
Thank you for your response sir :)
I got this error: Error 1 'CrystalDecisions.CrystalReports.Engine.ReportDocument' does not contain a definition for 'SetParameter' and no extension method 'SetParameter' accepting a first argument of type 'CrystalDecisions.CrystalReports.Engine.ReportDocument' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\cheche\My Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs 42 13 C:\...\WebSite2\


What is the reference for SetParameter. I google it but I can't find it..
Adam R Harris 4-Nov-10 10:05am    
http://msdn.microsoft.com/en-us/library/cc411356(VS.90).aspx

Crystal Reports Basic for Visual Studio 2008
Supported since: Crystal Reports .NET 9

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900