- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0 |
在VB6中使用水晶报表并动态设置数据源
首先引用Crystal Reports 9 ActiveX Designer Run Time Library再添加Crystal Repotr View Control 9控件在工程资源管理器中右键--添加--Crystal Reports 9 新建一个Crystal Reports9报表设置数据源后将要显示的字段加入报表内。
窗体代码部分:
Dim m_Report As New CrystalReport1 '(这个CrystalReport1是你建立的报表的名称)
Dim m_Connection As ADODB.Connection '(建立一个ADO连接)
Dim adoRS As ADODB.Recordset
Private Sub Form_Load()
Dim SQL As String
Dim strConnect As String
' Create and bind the ADO Recordset object
Set m_Connection = New ADODB.Connection
Set adoRS = New ADODB.Recordset
' Open the connection
strConnect = "你的数据库连接字符串"
m_Connection.Open strConnect
SQL = "查询语句"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
m_Report.Database.SetDataSource adoRS'(动态设置报表数据源)
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport '(显示报表)
Screen.MousePointer = vbDefault
End Sub
显示打印机设置动话框
报表名.PrinterSetup Me.hWnd
用代码设置纸张大小
报表名.PaperSize =crPaperA4
是否显示右上角水晶报表的图标
CRViewer1.EnableAnimationCtrl = Not CRViewer1.EnableAnimationCtrl
是否显示导出报表按钮
CRViewer1.EnableExportButton = Not CRViewer1.EnableExportButton
是否显示关闭按钮
CRViewer1.EnableCloseButton = Not CRViewer1.EnableCloseButton
是否显示左侧树列表
CRViewer1.EnableGroupTree = Not CRViewer1.EnableGroupTree
是否显示导航
CRViewer1.EnableNavigationControls = Not CRViewer1.EnableNavigationControls
是否显示弹出菜单
CRViewer1.EnablePopupMenu = Not CRViewer1.EnablePopupMenu
是否显示打印按钮
CRViewer1.EnablePrintButton = Not CRViewer1.EnablePrintButton
是否显示刷新按钮
CRViewer1.EnableRefreshButton = Not CRViewer1.EnableRefreshButton
是否显示工具栏
CRViewer1.EnableToolbar = Not CRViewer1.EnableToolbar
是否显示比例调整窗口
CRViewer1.EnableZoomControl = Not CRViewer1.EnableZoomControl
报表显示的样式
CRViewer1.DisplayBackgroundEdge = Not CRViewer1.DisplayBackgroundEdge
报表控件是否有边框
CRViewer1.DisplayBorder = Not CRViewer1.DisplayBorder
是否显示报表的选项卡
CRViewer1.DisplayTabs = Not CRViewer1.DisplayTabs
vb中调用水晶报表生成的*.rpt文件
CrystalReport1.ReportFileName = App.Path & "liuhan.rpt"
CrystalReport1.WindowTitle = "打印预览"
CrystalReport1.WindowState = crptMaximized '使打印预览窗口最大化********
CrystalReport1.Destination = crptToWindow '到窗口***********************
'CrystalReport1.Destination = crptToPrinter '到打印机********************
CrystalReport1.PrinterDriver = 1
CrystalReport1.PrintReport
解决水晶报表更新数据后需按刷新问题报表名.DiscardSavedData
此代码在VB6+SP5+Windows2000 Server下调试通过以上代码参考水晶报表9中文版
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |