欢迎光临
我们一直在努力

VB程序打印水晶报表的典型方法1-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

描述:

 

  本文介绍流行的一种vb程序打印水晶报表的方法,具有比较好的扩展性.

 

环境:

   ms sql server 2000  /  vb6  /  crystal report8.5

 

步骤

 

1: 建立odbc连接

 

2: 创建一个为crystal report检索数据的过程(procedure)

举例: (通过日期查询总额)

   if exists (select * from sysobjects where name = usp_testfjs)

            drop proc usp_testfjs

   go

   create proc usp_testfjs

            @strdate varchar(20)

   as

        select sum(tot_amt) as total_amount

        from trans_header

        where convert(varchar(10),bus_dt,120) = @strdate

   go

 

3. 创建使用procedure的crystal 报表

   步骤和创建一般报表相同,但是注意在选择数据源时,把options中的stored procedures勾上

  

4. 创建vb程序

   注意加入一个水晶报表控件(crystal report control)

   一段最简单的程序:

   例如:

   private sub command1_click()

        dim iret as integer

        crystalreport1.reset  /*reset data*/

 crystalreport1.reportfilename = app.path + “\totalamount.rpt”

/*link the crystal report control with actual rpt file */

        crystalreport1.storedprocparam(0)= format(trim$(dtpicker1.value), “yyyy-mm-dd”)

/*assign the parameter*/

        crystalreport1.windowstate = crptmaximized

        crystalreport1.windowtitle = “hello”

        iret = crystalreport1.printreport

/*retrieve the data and display the printpreview screen */

 

总结:

   这个方法实现了水晶报表和vb程序的独立性,用户对于报表格式的改变将被局限于水晶报表的修改范围中. 建议大家采用这种方法.

  

 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » VB程序打印水晶报表的典型方法1-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章