Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports 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 October 13th, 2006, 06:53 AM
Registered User
 
Join Date: Oct 2006
Location: Ahmedabad, Gujarat, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shriji.1111
Default Crystal Report Parameter pass from c#

Dear Friends,
How to pass parameters in c# to Crystal Report.
I already create Crystal Reprot using store Procedure.
But How can i pass parameters to that reoprts.
*********************************************
My Code: -
==========
Add Librarioes: -
---------
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
-----------
sqlcmd.CommandText = "Sp_Report1";
sqlcmd.CommandType = CommandType.StoredProcedure;

sqlcmd.Connection = con;
con.Open();

string path;
ReportDocument orpt = new ReportDocument();

path = Request.PhysicalApplicationPath;
path = path + "SellPro.rpt";
orpt.Load(path);

            CrystalDecisions.Shared.DiskFileDestinationOptions diskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions ();

            orpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableD ocFormat;
            orpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.Disk File;

path = Request.PhysicalApplicationPath;
diskOpts.DiskFileName = path + "1.pdf";
orpt.ExportOptions.DestinationOptions = diskOpts;

            orpt.Export();

************************************************** ***
What i do?



Brijesh Shah

Brijesh Shah
Reply With Quote
  #2 (permalink)  
Old October 13th, 2006, 11:16 AM
Registered User
 
Join Date: Oct 2006
Location: Edmonds, WA, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I've got some .NET 2003 C# code that may help you. The code sample below extracts an HTML form value passed to the aspx page, then assigns it as a Parameter Field (PF) which is passed to my sprocs, plus assigns ADO connection info to the report datasources. (My report is actually a master report with a bunch of subreports that produce a single PDF.) The main parameter, @strSprocParameter, is what gets passed into the sprocs. You can use add'l params the same way, like my bSubReportX params. In my case, the same param is passed to all my sprocs. You can set up subreport parameter fields in exactly the same way, linking the strParameter param to each subreport's param. I believe you can set up more than 1 param, but I didn't need to. Another quick-n-dirty method is to pass a string that you can break up into an array of params in your sproc, but that's kind of kludgy. :)


using CrystalDecisions;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;

private void Page_Load(object sender, System.EventArgs e)
{
    // Put user code to initialize the page here
    int i, j;
    CrystalDecisions.CrystalReports.Engine.ReportDocum ent objReport
        = new CrystalDecisions.CrystalReports.Engine.ReportDocum ent();
    CrystalDecisions.Shared.ConnectionInfo conn = new ConnectionInfo();
    CrystalDecisions.CrystalReports.Engine.Table myTable;
    CrystalDecisions.Shared.TableLogOnInfo myLog;
    System.IO.MemoryStream ios;
    ios = new System.IO.MemoryStream();

    // retrieve HTML form fields passed to the aspx page
    string strParameter = Request.Form.Get("txtParameter");
    string strReportPath = Request.Form.Get("txtReportPath");

    // which subreports are to be generated? each is an HTML checkbox
    bool bSubReportA = Request.Form.Get("chkSubReportA") == "on" ? true : false;
    bool bSubReportB = Request.Form.Get("chkSubReportB") == "on" ? true : false;
    bool bSubReportC = Request.Form.Get("chkSubReportC") == "on" ? true : false;

    // load the report and set its runtime parameters
    // Note: each needs to be added to the report as a Parameter Field, and the
    objReport.Load(strReportPath);//, OpenReportMethod.OpenReportByTempCopy);
    objReport.Refresh(); // needed so report will accept new parameters
    objReport.SetParameterValue("@strSprocParameter", strParameter);
    objReport.SetParameterValue("bSubReportA", bSubReportA);
    objReport.SetParameterValue("bSubReportB", bSubReportB);
    objReport.SetParameterValue("bSubReportC", bSubReportC);

    // assign the same database connection for each report
    conn.ServerName = "My_System_DSN";
    conn.DatabaseName = "MY_Database";
    conn.UserID = "SomeUserID";
    conn.Password = "SomePassword";
    for (i=0; i<objReport.Database.Tables.Count; i++) {
        myTable = objReport.Database.Tables[i];
        myLog = myTable.LogOnInfo;
        myLog.ConnectionInfo = conn;
        myTable.ApplyLogOnInfo(myLog);
        myTable.Location = myLog.TableName;
    }

    // execute the report and export to a PDF memory buffer
    ios = (MemoryStream)objReport.ExportToStream(CrystalDeci sions.Shared.ExportFormatType.PortableDocFormat);
    Response.Clear();
    Response.Buffer= true;
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(ios.ToArray());
}

I hope that helps. The 1st parameter is the std type set up according to the directions in the CR help docs built into both the MSDN help and CR's Report Designer (the standalone design software). That's why you see the "@" in its name. The others are extra parameters I added so I can include/exclude any of the subreports.
Reply With Quote
  #3 (permalink)  
Old October 16th, 2006, 03:55 AM
Registered User
 
Join Date: Oct 2006
Location: Ahmedabad, Gujarat, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shriji.1111
Default

Thanks for Reply.


Brijesh Shah
Reply With Quote
  #4 (permalink)  
Old April 14th, 2009, 06:44 AM
hu_yang
Guest
 
Posts: n/a
Default C# crystal report parameter

ParameterFieldDefinitions crParameterFieldDefinitions ;
ParameterFieldDefinition crParameterFieldDefinition ;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = "Your Value"
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["Your Field"];
crParameterValues = crParameterFieldDefinition.CurrentValues;

crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crPa rameterValues);

http://csharp.net-informations.com/c...-parameter.htm

hu.
Reply With Quote
  #5 (permalink)  
Old June 14th, 2011, 11:38 AM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much hu_yang, your code saved my life!
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
How to pass parameter to a crystal report using c# preetakrish BOOK: Professional Crystal Reports for VS.NET 16 November 19th, 2009 05:26 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 04:13 AM.


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