TonyZhao

【.Net】水晶报表CrystalReport粗浅入门

VB6代码大概是这样的:

  crystalreport1.Connect:=\'dsn=xxx;uid=yyy;pwd=zzz;dsq=aaa\';
  crystalreport1.DiscardSavedData:=true;
  crystalreport1.SQLQuery:=\'select * from ttt\';
  crystalreport1.ReportFileName:=\'d:\rrr.rpt\';
  crystalreport1.Destination:=crpttowindow;
  crystalreport1.Action:=1;

 

 

VS2010没有集成,需要下载,下载地址:

http://scn.sap.com/docs/DOC-7824

 

新增DataSet,定义表结构。

 

我的工程师从VB6升级上来的已经有.rpt模板文件,

把.rpt模板文件添加到工程中,修改rpt绑定的表为刚才定义的DataSet中的表。

修改rpt各显示列绑定表字段。

保存修改。

 

在代码中添加如下代码,即可实现打印:

        Dim cr As New <rpt文件>
        Dim crv As New CrystalReportViewer
        cr.Load(<rpt文件全路径>)
        cr.SetDataSource(<DataTable>)
        crv.ReportSource = cr
        crv.PrintReport()

 

我要实现的功能很简单,只实现数据库表的全部打印功能,没有特殊处理,也没有在RPT里写代码的必要。只是简单实现打印。

其实VB6是采用推模式,但是为了简单.net被我改成了拉模式。

实现功能就好,没有继续深入研究。毕竟工作进度摆在眼前。

 

参考:

http://www.cnblogs.com/MarkRao/archive/2012/10/29/cr1.html

http://scn.sap.com/docs/DOC-7824

http://blog.csdn.net/haibodotnet/article/details/21570

 

分类:

技术点:

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2022-03-08
  • 2021-10-19
  • 2021-07-18
  • 2021-12-25
猜你喜欢
  • 2021-08-25
  • 2021-06-19
  • 2022-12-23
  • 2021-08-14
  • 2022-01-30
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案