当前位置:网站首页>C#实现水晶报表绑定数据并实现打印
C#实现水晶报表绑定数据并实现打印
2022-06-24 23:11:00 【coder i++】
转载:https://blog.csdn.net/weixin_30340819/article/details/97184698
1.新建水晶报表并完成制作
2.
新建window窗体,并在窗体里面放置一个CrystalReportViewer控件,单击右上角的
小三角行,然后选择需要展示的报表,并设置报表的路径。
代码绑定:
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;
要实现打印功能,还需要修改(这个打印功能不是CrystalReportViewer里面自带的)
//获取数据并绑定DataSet
//打印功能
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);
边栏推荐
- How to quickly familiarize yourself with the code when you join a new company?
- 云原生数据库VS传统数据库
- 做软件安全测试的作用,如何寻找软件安全测试公司出具报告?
- 消息称一加将很快更新TWS耳塞、智能手表和手环产品线
- 折叠屏将成国产手机分食苹果市场的重要武器
- Resolution of cross reference in IDA
- QT package the EXE file to solve the problem that "the program input point \u zdapvj cannot be located in the dynamic link library qt5cored.dll"
- random list随机生成不重复数
- 产业互联网的概念里有「互联网」字眼,但却是一个和互联网并不关联的存在
- Summary of knowledge points of computer level III (database) test preparation topics
猜你喜欢

Random list random generation of non repeating numbers

Once beego failed to find bee after passing the go get command Exe's pit

使用ShaderGraph制作边缘融合粒子Shader的启示

常用的软件测试工具清单,请查收。

Once beego failed to find bee after passing the go get command Exe's pit

Please run IDA with elevated permissons for local debugging.

【Proteus仿真】Arduino UNO+数码管显示4x4键盘矩阵按键

一线城市软件测试工资——你拖后腿了吗

Experience of epidemic prevention and control, home office and online teaching | community essay solicitation

会自动化—10K,能做自动化—20K,你搞懂自动化测试没有?
随机推荐
一线城市软件测试工资——你拖后腿了吗
PyTorch学习笔记(七)------------------ Vision Transformer
vim的Dirvish中文文档
AI服装生成,帮你完成服装设计的最后一步
The role of software security testing, how to find a software security testing company to issue a report?
调用系统函数安全方案
npm包发布详细教程
Lizuofan, co-founder of nonconvex: Taking quantification as his lifelong career
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
算力服务网络:一场多元融合的系统革命
做软件安全测试的作用,如何寻找软件安全测试公司出具报告?
保险APP适老化服务评测分析2022第06期
PE文件基础结构梳理
UnityShader入门精要——表面着色器
Is the compass reliable? Is it safe to open a securities account?
当一个接口出现异常时候,你是如何分析异常的?
Viewing MySQL password on Linux_ MySQL forgets password "suggestions collection" under Linux
Network planning | [four network layers] knowledge points and examples
How to quickly familiarize yourself with the code when you join a new company?
3年测试经验,连简历上真正需要什么都没搞明白,张口就要20k?