Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > BOOK: Professional Crystal Reports for VS.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 24th, 2004, 05:35 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old June 30th, 2005, 12:24 PM
Registered User
 
Join Date: Jun 2005
Location: Baroda, Guijarat, India.
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
Reply With Quote
  #3 (permalink)  
Old July 5th, 2005, 05:40 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old March 14th, 2006, 04:53 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
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.

Reply With Quote
  #5 (permalink)  
Old March 14th, 2006, 04:54 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
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?

Reply With Quote
  #6 (permalink)  
Old March 30th, 2006, 03:09 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
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();
}
Reply With Quote
  #7 (permalink)  
Old April 29th, 2006, 03:14 PM
Registered User
 
Join Date: Apr 2006
Location: , , Jordan.
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



Reply With Quote
  #8 (permalink)  
Old April 29th, 2006, 03:19 PM
Registered User
 
Join Date: Apr 2006
Location: , , Jordan.
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




Reply With Quote
  #9 (permalink)  
Old July 5th, 2007, 01:22 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
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.


Reply With Quote
  #10 (permalink)  
Old October 9th, 2007, 08:22 AM
Registered User
 
Join Date: Oct 2007
Location: , , .
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();
        }



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:59 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.