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

