Crystal Report is a great Reporting Tool we are using in DotNet to print Reports.Here we will explain how to print a report using Crystal Report in Windows Forms Application.
In this article we will explain how to print report using crystal Report in windows application. For using crystal Report in the Windows application please follow the following steps to add it.
Let's start with a windows project named "CanteenManagement" in the solution and Crystal Report can be added as follows:
Image2-Choose Crystal Reports
Image3:-Choose Standard Report
:-Choose Microsoft OLEDB Provider for SqlServer.
Image6:-Provide the proper database information.
Image7:-After Successfully connecting with DB add the table where you want to work.
After that if you want to chose column then choose either click finish
Image8:-Now go to the Crystal Report and design as per your Requirenent.
Image9:-Now we have to show the Report in "Employee Lunch\Dinner Report" so lets go to this menu and add a form there to show report.
Image10:-Add a form as print as shown below
Image11:-Add a Crystal Report viewer in the form.
Now here is the code to populate the PRINT page on Clicking "EmployeeLunch\Dinner Booking Entry" menu in MDI parent form.
private void employeeLunchDinnerReportToolStripMenuItem_Click(object sender, EventArgs e)
Print obj = new Print();
Now, when the print page will load the report will generate so just write the following code in crystalReportViewer1_Load event.
private void crystalReportViewer1_Load(object sender, EventArgs e)
Print p = new Print();
Report rpt = new Report();
dt = p.showdata();
this.crystalReportViewer1.ReportSource = rpt;
Here is showdata method.
public DataTable showdata()
string Query = "select * from BookMeal";
dt = obj.ShowData(Query);
if (dt.Rows.Count > 0)
Passing query to one CanteenBAL.cs here is that code.
public DataTable ShowData(string query)
da = new SqlDataAdapter(query, CanteenBAL.connection());
dt = new DataTable();
Now just save the programme and run the project it will show the report as follow.
ConclusionIn this way we can generate crystal report in windows form.