Using Crystal report in C# step by step
In this tutorial we will see how to create and print Crystal Reports in C# Windows Forms application.
First, add a preview button in the main form Form1, and in the 2nd form Form2 add CrystalReportViewer and set its Modifiers property to Public:
Then add a blank Crystal Report to the project:
Choose Database fields from Field Explorer, browse to your Database file, then drag and drop the fields you want to show in the report like this:
Finally, add this code to PreviewButton click event:
For more explanation, watch this video:
First, add a preview button in the main form Form1, and in the 2nd form Form2 add CrystalReportViewer and set its Modifiers property to Public:
Then add a blank Crystal Report to the project:
Choose Database fields from Field Explorer, browse to your Database file, then drag and drop the fields you want to show in the report like this:
Finally, add this code to PreviewButton click event:
private void PreviewButton_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
if (con.State != ConnectionState.Open)
{
con.Open();
}
string s = "SELECT * FROM Employee";
OleDbCommand cmd = new OleDbCommand(s, con);
OleDbDataAdapter adap = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds, "Employee");
CrystalReport1 cr1 = new CrystalReport1();
cr1.SetDataSource(ds);
f2.crystalReportViewer1.ReportSource = cr1;
f2.crystalReportViewer1.Refresh();
con.Close();
}
For more explanation, watch this video:
Using Crystal report in C# step by step
Reviewed by Bloggeur DZ
on
03:34
Rating:
Thank you sir.
RépondreSupprimerVery helpful tutorial
RépondreSupprimerThanks for this explanation, it helps me
RépondreSupprimer