Steps:
1. Create a new dataset and place the table in the database into DataSet2.xsd.
2. Create a New Crystal Report and follow the Wizard to create the Crystal Report, as shown below:
3. Create a new WINDOWS form, place a CrystalReportViewer control in the form, click the small triangle row in the upper right corner, select the report to be displayed, and set the report path,
As follows:
4. Bind the background code:
View source Print?
01
// Start binding
02
String sql=
""
03
sql =
"Select * from table name"
04
SqlConnection con=
new
Sqlconnection(
"Data connection string"
);
05
SqlDataApter da=
new
SqlDataApter(sql,con);
06
DataSet ds=
new
DataSet();
07
CrystalReport1 cry=
new
CrystalReport1 ();
08
con.Open()
09
da.Fill(ds,
"dgv"
)
10
cry.SetDataSource(ds.Tables(
"dgv"
))
11
CrystalReportViewer1.ReportSource = cry
12
// End binding
13
To implement the print function, you need to modify the following: (This printing function is not included in CrystalReportViewer1 ):
View source