Passing parameter to Crytal report in ASP .NET C#

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
xuanthinhAsked:
Who is Participating?
 
dylanyeeCommented:
>> 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
 
SpykairCommented:
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
xuanthinhAuthor Commented:
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
 
dylanyeeCommented:
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
 
xuanthinhAuthor Commented:
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
 
dylanyeeCommented:
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
 
xuanthinhAuthor Commented:
hi dylanyee,

I have already make my report now. Thank you very much
0
 
xuanthinhAuthor Commented:
sorry dylanyee,

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

Thank mlmcc also
0
 
dylanyeeCommented:
thats all right, glad we we could help you up :)

dylan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.