Wrox Programmer Forums
|
BOOK: Professional Crystal Reports for VS.NET
This is the forum to discuss the Wrox book Professional Crystal Reports for Visual Studio .NET by David McAmis; ISBN: 9780764544033
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Crystal Reports for VS.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2004, 05:35 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to pass parameter to a crystal report using c#

Hi friends,

Could anyone help me how to pass parameter in crystal report using c#.net?

Thanks a lot
preetha
 
Old June 30th, 2005, 12:24 PM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sanket Send a message via Yahoo to sanket
Default

Quote:
quote:Originally posted by preetakrish
 Hi friends,

Could anyone help me how to pass parameter in crystal report using c#.net?
im new to this.i need a sample code
Thanks a lot
preetha

Sanket's
Jai Swaminarayan
 
Old July 5th, 2005, 05:40 AM
Registered User
 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I presume you are using a crystal reports viewer from within a c# form.

Anyway, this is how I passed a formula field so I guess parameter fields are the same.


ackPrt newReport= new ackPrt();
newReport.DataDefinition.FormulaFields[0].Text="\"ACK\"";
crystalReportViewer1.ReportSource = newReport;

the 1st and 3rd lines should be ok for you.
the important line is line 2. I have created a formula field called reportType. The code in line 2 places the text ACK into the first formula field (a zero seeded array).

Hope that helps

 
Old March 14th, 2006, 04:53 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Happyslug,

You are passing a parameter as a formula within Crystal Report from C#.

What about passing a parameter as a parameter within Crystal Report from C#? I'm encountering a lot of problem at my end. I'm unsure if my C# code is incorrect or the Crystal Report I created is incorrect.

A stanza of my C# code is given below:

ParameterDiscreteValue crtParamDiscreteValue;
ParameterField crtParamField;
ParameterFields crtParamFields;

crtParamDiscreteValue = new ParameterDiscreteValue();
crtParamField = new ParameterField();
crtParamFields = new ParameterFields();

crtParamDiscreteValue.Value = "ABC";
crtParamField.ParameterFieldName = "source";
crtParamField.CurrentValues.Add(crtParamDiscreteVa lue);
crtParamFields.Add(crtParamField);

crtRptViewer.ParameterFieldInfo = crtParamFields;

Within Crystal Report itself, I have created a parameter called "source" as well as using the "Select Expert" to refine my search criterion to a specific column of the table I am drawing the data from.

Yet, I get the error: Query Engine Error.

I am at a loss now. Can you kindly advise me?

Thanks.

 
Old March 14th, 2006, 04:54 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using Visual Studio .NET 2003 and Crystal Report XI. I am wondering if this is one of the several bugs reported for Crystal Report XI?

 
Old March 30th, 2006, 03:09 PM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have been selfish TAKE TAKE TAKE, a

Now I can give. (after many hours if research)

This worked for me.

private void Page_Load(object sender, System.EventArgs e)
{
    CrystalReportViewer1.DataBind();
    SetParameterFields();
}

protected void SetParameterFields ()
{
    ParameterField f1 = CrystalReportViewer1.ParameterFieldInfo[0];
    ParameterDiscreteValue v1 = new ParameterDiscreteValue();
    v1.Value = Request.QueryString["Whatever"]; //Or Session("Whatever")
    f1.CurrentValues.Add(v1);
    CrystalReportViewer1.RefreshReport();
}
 
Old April 29th, 2006, 03:14 PM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by preetakrish
 Hi friends,

Could anyone help me how to pass parameter in crystal report using c#.net?
im new to this.i need a sample code
Thanks a lot
preetha

I think I have a solution that does not make errors if U are interested :D


and that is the solution
Parameter_mohammad.ParameterFieldName)
Dim x As New CrystalReport1

x.SetParameterValue(x.Parameter_mohammad.Parameter FieldName,5)

'my point is that the parameter field(mohammad) becomes a property
'of the crystal report object(x.Parameter_mohammad) and the you take
'the parameter field name(x.Parameter_mohammad.ParameterFieldName)
' 5 is the value you want to assign
        CrystalReportViewer1.ReportSource = x



 
Old April 29th, 2006, 03:19 PM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I have a solution that does not make errors if U are interested


and that is the solution
Dim x As New CrystalReport1

x.SetParameterValue(x.Parameter_mohammad.Parameter FieldName,5)
CrystalReportViewer1.ReportSource = x



the following is explaination not part of the solution:

'my point is that the parameter field(mohammad) becomes a property
'of the crystal report object(x.Parameter_mohammad) and the you take
'the parameter field name(x.Parameter_mohammad.ParameterFieldName)
' 5 is the value you want to assign




 
Old July 5th, 2007, 01:22 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i found that the last line

CrystalReportViewer1.RefreshReport();

refreshed my whole report, and as a result, deleted what i just assigned.


 
Old October 9th, 2007, 08:22 AM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:Dhi everyone....following is the code to successfully
    pass one or many parameters of any datatype from C# to Crystal Report...One can write the code in the page load event...

if (Session["RPT_NAME"] != null)
        {

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath((string)Session["RPT_NAME"]));


            int cnt = rpt.DataDefinition.ParameterFields.Count;
            for (int i = 0; i < cnt; i++)
            {
                ParameterValues myvals = new ParameterValues();
                ParameterDiscreteValue myDiscrete = new ParameterDiscreteValue();

                switch (rpt.DataDefinition.ParameterFields[i].ParameterValueKind)
                {
                    case CrystalDecisions.Shared.ParameterValueKind.DateTim eParameter:
                        myDiscrete.Value = Convert.ToDateTime(Request.QueryString[i]);
                        break;

                    case CrystalDecisions.Shared.ParameterValueKind.Boolean Parameter:
                        myDiscrete.Value = bool.Parse(Request.QueryString[i]);
                        break;
                    case CrystalDecisions.Shared.ParameterValueKind.DatePar ameter:
                        myDiscrete.Value = Convert.ToDateTime(Request.QueryString[i]);
                        break;
                    case CrystalDecisions.Shared.ParameterValueKind.NumberP arameter:
                        myDiscrete.Value = int.Parse(Request.QueryString[i]);
                        break;
                    case CrystalDecisions.Shared.ParameterValueKind.StringP arameter:
                        myDiscrete.Value = Convert.ToString((Request.QueryString[i]));
                        break;
                }
                myvals.Add(myDiscrete);
                rpt.DataDefinition.ParameterFields[i].ApplyCurrentValues(myvals);
            }
            CrystalReportViewer1.ReportSource = rpt;
            CrystalReportViewer1.DataBind();
        }








Similar Threads
Thread Thread Starter Forum Replies Last Post
Crystal Report Parameter pass from c# shriji.1111 Crystal Reports 4 June 14th, 2011 11:38 AM
pass parameter in crystal report srivigdev C# 3 April 14th, 2008 12:11 PM
How to pass parameter to sub-report . azeerum Access 1 January 3rd, 2005 04:26 PM
How to Pass parameter to chart in crystal Report. simsimlhr C# 3 April 12th, 2004 11:04 AM
Pass parameter to store procedure & Crystal Report quinn Classic ASP Professional 0 March 10th, 2004 02:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.