【.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

 

posted on 2016-03-09 11:09  tony_cyou  阅读(745)  评论(0编辑  收藏  举报

导航