当前位置:网站首页>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);
边栏推荐
- [live review] battle code pioneer phase 7: how third-party application developers contribute to open source
- 当人们用互联网式的思维和视角来看待产业互联网的时候,其实已陷入到了死胡同
- 使用ShaderGraph制作边缘融合粒子Shader的启示
- Experience of epidemic prevention and control, home office and online teaching | community essay solicitation
- MySQL command backup
- AI服装生成,帮你完成服装设计的最后一步
- Convert string array to list collection
- npm包发布详细教程
- It's 2022, and you still don't know what performance testing is?
- How to quickly familiarize yourself with the code when you join a new company?
猜你喜欢
【Proteus仿真】Arduino UNO+数码管显示4x4键盘矩阵按键
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source
Random list random generation of non repeating numbers
一线城市软件测试工资——你拖后腿了吗
Software testing salary in first tier cities - are you dragging your feet
leecode学习笔记-机器人走到终点的最短路径
File system - basic knowledge of disk and detailed introduction to FAT32 file system
1-6搭建Win7虚拟机环境
Yarn: unable to load file c:\users\xxx\appdata\roaming\npm\yarn PS1 because running scripts is prohibited on this system
Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
随机推荐
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"
分布式事务解决方案和代码落地
Groovy之高级用法
What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
Android Internet of things application development (smart Park) - set sensor threshold dialog interface
Computing service network: a systematic revolution of multi integration
计网 | 【四 网络层】知识点及例题
[i.mx6ul] u-boot migration (VI) network driver modification lan8720a
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(3)—— 把数据库设置为归档模式
Squid 代理服务器之 ACL 访问控制
【FPGA】串口以命令控制温度采集
都2022年了,你还不了解什么是性能测试?
Detailed explanation of cache (for the postgraduate entrance examination of XD)
【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
UnityShader入门精要——表面着色器
常用的软件测试工具清单,请查收。
【STL源码剖析】配置器(待补充)
jwt
一线城市软件测试工资——你拖后腿了吗
Folding screen will become an important weapon for domestic mobile phones to share the apple market