PULL Mode
1. Create a dataset: Right-click Project/Add/select dataset/name ds_test/click Add
2. Create a From form Form1
(1) Add a crystalReportViewer1 control to it.
(2) Add the sqlDataAdapter control (automatically generated step by step according to the pop-up Wizard)
(3) generate a dataset Based on the created sqlDataAdapter.
3. Create a report: Right-click Project/Add item/select crystalReport/name CrystalReport1.rpt/click Add
(1) In field resource manager, right-click "database Field"/select "Database Expert"/expand "project data"/expand "ADO. NET dataset"/expand
Add the generated dataset to the right box/OK
(2) Expand "database fields"/expand the following table/drag the fields in the table to the report for Layout Design
4. Define the fromdomainload () event as follows:
Private void Form1_Load (object sender, EventArgs e)
{
// PULL Mode
This. sqlDataAdapter1.Fill (this. ds_test); // ds_test is automatically generated based on the data adapter.
CrystalReport1 cr = new CrystalReport1 ();
Cr. SetDataSource (this. ds_test.Tables [0]);
CrystalReportViewer1.ReportSource = cr;
}
PUSH mode
1. Create a dataset: Right-click Project/Add/select dataset/name ds_test/click Add
2. Create a From form Form1
(1) Add a crystalReportViewer1 control to it.
(2) Add the sqlDataAdapter control (automatically generated step by step according to the pop-up Wizard)
(3) generate a dataset Based on the created sqlDataAdapter.
3. Create a report: Right-click Project/Add item/select crystalReport/name CrystalReport1.rpt/click Add
(1) In field resource manager, right-click "database Field"/select "Database Expert"/expand "project data"/expand "ADO. NET dataset"/expand
Add the generated dataset ds_test to the right box/OK
(2) Expand "database fields"/expand the following table/drag the fields in the table to the report for Layout Design
4. Define the fromdomainload () event as follows:
SqlConnection conn = new SqlConnection ("server =; integrated security = sspi; database = ");
SqlDataAdapter da;
DataSet ds = new DataSet ();
Private void Form1_Load (object sender, EventArgs e)
{
// PUSH mode
Da = new SqlDataAdapter ("SQL query statement", conn );
Da. Fill (ds );
CrystalReport1 cr = new crystalReport1 ();
Cr. SetDataSource (ds. Tables [0]);
CrystalReportView1.ReportSource = cr;
}