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

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus