当前位置:网站首页>C # realizes crystal report binding data and printing

C # realizes crystal report binding data and printing

2022-06-25 02:40:00 coder i++

Reprint :https://blog.csdn.net/weixin_30340819/article/details/97184698

1. Create a new crystal report and complete the production
2.
newly build window forms , And put a... In the form CrystalReportViewer Control , Click on the
Small triangle row , Then select the report to be displayed , And set the path of the report .
Code binding :
string sql = “select * from tablename”;
SqlConnection conn = new SqlConnection(conn);
SqlDataAdapter da = new SqlAdapter(sql,conn);
DataSet ds = new DataSet();
CrystalReport1 cry = new CrystralReport1();
conn.Open();
da.Fill(ds,“dgv”);
cry.SetDataSource(ds.Tables[“dgv”]);
CrystalReportViewer1.ReportSource = cry;

To realize the printing function , It needs to be revised ( This print function is not CrystalReportViewer It comes with )
// Get data and bind DataSet
// Printing function
PritnDocument print = new PrintDocument();
ReportDocument rd = new ReportDocument();
rd.Load(Application.StartupPath+“\CrystalReport1.rpt”);
rd.SetDatabaseLogin(“sa”,“userpwd”);
rd.SetDataSource(ds);
string printer = print.PrintSettings.PrinterName;
rd.PrintOptions.PrinterName = printer;
rd.PrintToPrinter(1,true,0,0);

原网站

版权声明
本文为[coder i++]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242311324779.html