Technology Articles

The science of today is the technology of tomorrow. Browse Technology related articles.

Dot. NET Articles

Browse the Dot.NET technical articles.

Web Design & Development

Browse Web Design & Development Articles which includes Technologies of Drupal, Joomla, CodeIgnitor, JQUERY, CMS, etc.

Health Articles

Browse Health Tips & Articles

Showing posts with label Crystal Report. Show all posts
Showing posts with label Crystal Report. Show all posts

Thursday, March 4, 2010

How to change Formula Field Variables in Crystal Report Programmatically


Open the crystal report you have just created in your project, and from the Field Explorer -> Formula Fields, right click and create Two new Formula Field Variables, lets name it as "parameter1" and "parameter2" respectively. Then drag and drop inside the Crystal Report and place it anywhere according to your need.

Then, use the below code (assume if we need to pass "Hello" & "How are you?" during runtime)

ReportDocument ReportDoc = new ReportDocument();
ReportDoc.Load(Server.MapPath("~") + "\\CrystalReport1.rpt");

List paramList = List();
paramList.Add("Hello");
paramList.Add("How are you?");

for (int i = 1; i < 2; i++)
           if (ReportDoc.DataDefinition.FormulaFields[i-1].FormulaName 
                                                                           == "{" + "@parameter" + i + "}")
                      ReportDoc.DataDefinition.FormulaFields[i-1].Text 

                                                                                    = "\"" + paramList[i-1] + "\"";




Guide to Excel Reporting with MS SQL data using Crystal Report


First of all you need to create a New Data Set object from the Add new Item. Inside the Data set you need to create a new Table Adapter which will Fill data to a Data Table.

Then you need to create a new Crystal Report File from Add new Item. In the Crystal report, from the Field Explorer -> Database Fields, now you will able to see the created Data Table with all the Column Elements selected.

Select the Column Elements needed, and add them to your Crystal Report and arrange them to your specific need. Using Crystal Reports->Design->Printer Setup, you can adjust the size of the Crystal Report according to your need. Also to make it a template for Excel, you need to Suppress the Page Footer from the Section Expert.
Then the below given Block of code is used for Excel Reporting.

try {
TempDataSetTableAdapters.TempTableAdapter temp = new MyProject.TempDataSetTableAdapters.TempTableAdapter();
TempDataSet.TempDataTable tempTable = new TempDataSet.TempDataTable();

DataTable DT = tempTable;
temp.Fill(tempTable);

ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("~") + "\\TempReport.rpt");
rpt.SetDataSource(DT);

Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();

rpt.ExportToHttpResponse(ExportFormatType.Excel, Response, true, "Report");
}
catch (Exception ex){
}