VB程序打印水晶报表的典型方法1

王朝vb·作者佚名  2006-01-08
宽屏版  字体: |||超大  

描述:

本文介绍流行的一种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程序的独立性,用户对于报表格式的改变将被局限于水晶报表的修改范围中. 建议大家采用这种方法.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有