?
Solved

Passing parameter to Crytal report in ASP .NET C#

Posted on 2006-03-26
11
Medium Priority
?
2,635 Views
Last Modified: 2008-02-01
Hi all,

I intend to build report by Crystal Report in ASP .NET C#. But I don't know how to passing parameter to report. For example: I want to select condition in the web form, and then depend that condition was selected I will make sql command and passing to the report.

And good more if I can make dynamic report (design report at runtime).

Please help me

Thank you very much
0
Comment
Question by:xuanthinh
10 Comments
 
LVL 10

Expert Comment

by:Spykair
ID: 16297646
0
 
LVL 8

Accepted Solution

by:
dylanyee earned 2000 total points
ID: 16297833
>> I want to select condition in the web form, and then depend that condition was selected
>> I will make sql command and passing to the report
Are you saying that you want to build the sql query based on user's input then bind the result data to report? You could find some example from here:
http://support.businessobjects.com/communityCS/FilesAndUpdates/sample_applications_for_.NET_developers.pdf.asp?recDnlReq=Record&dnlPath=sample_applications_for_.NET_developers.pdf

>> And good more if I can make dynamic report (design report at runtime).
You could use RDC (Report Design COmponent) to do so. but it won't be easy. Some example here:
http://support.businessobjects.com/communityCS/FilesAndUpdates/sample_applications_for_COM_developers.pdf.asp?recDnlReq=Record&dnlPath=sample_applications_for_COM_developers.pdf

dylan
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 16307434
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Author Comment

by:xuanthinh
ID: 16308853
Hi all,

Thank for your help. Now I can use the below code to passing parameter to Crystal report.
But my sql is complex command that select data from more than one tables and the adoOleDbDataAdapter.Fill require srcTable. I don't want to create a table have structure like a sql command (that table have not any data and do not use in any job and each sql command I have a table like that). Is there any way to solve this problem? Please help me!

                  string connectionString= "";
                  connectionString = "Provider=SQLOLEDB;";
            connectionString += "Server=TH_NGANV;Database=pubs;";
                  connectionString += "User ID=sa;Password=";

                  //Create and open a connection using the connection string
                  adoOleDbConnection = new OleDbConnection(connectionString);

                  //Build a SQL statement to query the datasource
                  string sqlString = "";
            sqlString = "Select *  From authors where state = 'CA' and phone like '41%'";

                  //Retrieve the data using the SQL statement and existing connection
                  adoOleDbDataAdapter = new OleDbDataAdapter(sqlString, adoOleDbConnection);

                  //Create a instance of a Dataset
                  dataSet = new DataSet();

                  //Fill the dataset with the data retrieved.  The name of the table
                  //in the dataset must be the same as the table name in the report.
                  adoOleDbDataAdapter.Fill(dataSet, "authors");
                  
            
                  //Create an instance of the strongly-typed report object
                  crReportDocument = new CrystalReport1();

                  //Pass the populated dataset to the report
                  crReportDocument.SetDataSource(dataSet);

                  //Set the viewer to the report object to be previewed.
                  CrystalReportViewer1.ReportSource = crReportDocument;
0
 
LVL 8

Expert Comment

by:dylanyee
ID: 16308927
xuanthinh, to design the CR, you don't have to create a physical table that have the same structure/field that returned by your sql query. instead, you could design your report by the sql query.
In your Crystal Report's database expert, after connected to your database, you should be able to see a "Add Command" object, double click that and you could put your sql query in, it will then create a "table" in your "field explorer->databases fields".

dylan
0
 

Author Comment

by:xuanthinh
ID: 16317623
hi dylanyee,

the problem is I don't Add command at design time. I have to create complex sql that select from more than one table at runtime. If you know please give me an example. I am new to CR in .NET C#

Thank you very much!
0
 
LVL 8

Expert Comment

by:dylanyee
ID: 16317702
How did you design your report now? Create a table that has exact fields return from your complex sql then link that to your report?

dylan
0
 

Author Comment

by:xuanthinh
ID: 16318556
hi dylanyee,

I have already make my report now. Thank you very much
0
 

Author Comment

by:xuanthinh
ID: 16318582
sorry dylanyee,

I press wrong button accept answer. Thank you very much for your help anyway.

Thank mlmcc also
0
 
LVL 8

Expert Comment

by:dylanyee
ID: 16318598
thats all right, glad we we could help you up :)

dylan
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question