Click here to Skip to main content
14,920,483 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have a asp.net web application that will contain one crystal report there i have defiend two selection criteria and also have two parameter for that selection criteria

like FirstName and second is LastName

now i want to know how to pass that parameter value to my cristal report using c#

I m using SAP CrystalReport for VSD2010 (CR13)
Posted
Updated 8-Mar-21 11:02am
v4

   
Comments
Tejas Vaishnav 21-Oct-11 9:09am
   
Its Give And Error Missing Parameter Value..
   
Comments
RaviRanjanKr 4-Nov-11 4:14am
   
Nice Link, My 5+
raj ch 7-Nov-11 2:15am
   
thanks RaviRanjanKr
check below

C#
report.Load(Server.MapPath("ReportsFolder")+ "\\YOURCRYSTALREPORT.rpt");            CrystalDecisions.Shared.ParameterValues pval1 = new ParameterValues();
CrystalDecisions.Shared.ParameterValues pval2 = new ParameterValues();
CrystalDecisions.Shared.ParameterValues pval3 = new ParameterValues();
CrystalDecisions.Shared.ParameterValues pval4 = new ParameterValues();

ParameterDiscreteValue pdisval1 = new ParameterDiscreteValue();
pdisval1.Value = strName;
pval1.Add(pdisval1);

ParameterDiscreteValue pdisval2 = new ParameterDiscreteValue();
pdisval2.Value = strID;
pval2.Add(pdisval2);

ParameterDiscreteValue pdisval3 = new ParameterDiscreteValue();
pdisval3.Value = Convert.ToInt32(ddlItems1.SelectedValue);
pval3.Add(pdisval3);
           
ParameterDiscreteValue pdisval4 = new ParameterDiscreteValue();
pdisval4.Value = Convert.ToInt32(ddlDepartments.SelectedValue);
pval4.Add(pdisval4);


report.DataDefinition.ParameterFields["@Parm1"].ApplyCurrentValues(pval1);
report.DataDefinition.ParameterFields["@Parm2"].ApplyCurrentValues(pval2);
report.DataDefinition.ParameterFields["@Parm3"].ApplyCurrentValues(pval3);
report.DataDefinition.ParameterFields["@Parm4"].ApplyCurrentValues(pval4);

//get connection string from web.config

CrystalDecisions.CrystalReports.Engine.Table myTable;
CrystalDecisions.Shared.ConnectionInfo conn = new ConnectionInfo();
CrystalDecisions.Shared.TableLogOnInfo myLog;
string strServer = ConfigurationSettings.AppSettings["SQLserver"].ToString();
string strDBName = ConfigurationSettings.AppSettings["SQLdatabaseName"].ToString();
string strUID = ConfigurationSettings.AppSettings["SQLUserName"].ToString();
string strPassword = ConfigurationSettings.AppSettings["SQLPassword"].ToString();

            conn.ServerName = strServer;
            conn.DatabaseName = strDBName;
            conn.UserID = strUID;
            conn.Password = strPassword;

            for (int i = 0; i < report.Database.Tables.Count; i++)
            {
                myTable = report.Database.Tables[i];
                myLog = myTable.LogOnInfo;
                myLog.ConnectionInfo = conn;
                myTable.ApplyLogOnInfo(myLog);
                myTable.Location = myLog.TableName;
            }

            CrystalReportViewer1.Visible = true;
            CrystalReportViewer1.DisplayGroupTree = false;

            CrystalReportViewer1.HasPageNavigationButtons = true;
            CrystalReportViewer1.HasCrystalLogo = false;
            CrystalReportViewer1.HasDrillUpButton = false;
            CrystalReportViewer1.HasSearchButton = false;
            CrystalReportViewer1.HasViewList = false;
            CrystalReportViewer1.HasToggleGroupTreeButton = false;
            CrystalReportViewer1.HasZoomFactorList = false;
            CrystalReportViewer1.ToolbarStyle.Width = new Unit("750px");

            CrystalReportViewer1.ReportSource = report;
   
v2
Comments
Tejas Vaishnav 21-Oct-11 9:09am
   
Its Give And Error Missing Parameter Value..
   
v4
Comments
Tejas Vaishnav 22-Oct-11 0:24am
   
Please Read a Question Care Fully...
I already Know what you show me, but i need to know how to pass parameter value defined in side selection criteria of cristal report
Fro Passing Paramter Value to Crystal Report i will use this and it will work for me...

C#
CRUserList CRUserListRPT = new CRUserList();
ParameterFields paraFileds = new ParameterFields();
ParameterField paraFiled = new ParameterField();                
ParameterDiscreteValue paraDescritValue;
ParameterField paraFiled1 = new ParameterField();
ParameterDiscreteValue paraDescritValue1;                

if (txtFirstName.Text.Trim() != "")
{
    paraFiled.Name = "FirstName";
    paraFiled.CurrentValues.Clear();
    paraDescritValue = new ParameterDiscreteValue();
    paraDescritValue.Value = txtFirstName.Text.Trim();
    paraFiled.CurrentValues.Add(paraDescritValue);
    paraFileds.Add(paraFiled);
}

if (txtLastName.Text.Trim() != "")
{
    paraFiled1.Name = "LastName";
    paraFiled1.CurrentValues.Clear();
    paraDescritValue1 = new ParameterDiscreteValue();
    paraDescritValue1.Value = txtLastName.Text.Trim();
    paraFiled1.CurrentValues.Add(paraDescritValue1);
    paraFileds.Add(paraFiled1);
}                
CRPTViewer.ParameterFieldInfo = paraFileds;
CRPTViewer.ReportSource = CRUserListRPT;


like this we can pass as many parameter as we declared in side report....
   
Comments
Member 8099391 14-May-13 12:30pm
   
"The name 'CRUserListRPT' does not exist in the current context"
Plz help...!! what is "CRUserListRPT"
Tejas Vaishnav 15-May-13 3:18am
   
Its my Crystal report object.. Name of my report. it will change according to your report

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