能否动态绑定crystal report 报表的数据库服务器名(或IP)?

fanjingfj 2009-03-14 09:04:35
用VB+SQL做了一个数据查询系统,并设计了一些报表(已绑定好服务器数据库),打印查询结果数据.运行OK!
现把数据库移到其它主机上(客户端通过读取INI文件可更改登录服务器名,查询数据没问题),但报表定制好为了以前服务器名。不能动态更改,所以不能查询打印数据。。
有没办法能改过来呀。。》?
各位帮帮忙,不胜感激!!
...全文
76 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jieweibin 2009-04-08
  • 打赏
  • 举报
回复
用 仅字段的方式就不用绑字数据库了,只需把查询的记录集作为数据源赋给水晶报表就行了,具体可以参考 阿泰的水晶报表博客,窗体代码大概如下(水晶报表),供参考
Private objCRApp As New CRAXDRT.Application '水晶报表应用程序对象
Private objCRReport As New CRAXDRT.Report '报表对象

Private Sub CRViewer91_PrintButtonClicked(UseDefault As Boolean)

Dim lngRet As Long
'不使用默认设置
UseDefault = False
'进行打印机设置
objCRReport.PrinterSetup Me.hwnd
'直接打印(注意True/False的设置,主要是为了控制前一对话框取消的情况)
objCRReport.PrintOutEx True
End Sub

Private Sub Form_Load()
Dim rst As New ADODB.Recordset
Dim props As CRAXDRT.ConnectionProperties '报表数据源参数集
Dim prop As CRAXDRT.ConnectionProperty '报表数据源参数
'--------------------------------------------------
'构建与定义的记录集对应的数据集结构来模拟一次数据库操作
'以下的操作可以替换成任意的过程,最终目的就是处理成一个记录集
'作为报表的数据来源
'--------------------------------------------------
Set rst = New ADODB.Recordset
rst.Open "pjrpt", db, adOpenKeyset, adLockOptimistic

'创建报表
'--------------------------------------------------
'加载报表模板
Set objCRReport = objCRApp.OpenReport(App.Path & "\PjRpt.rpt", 1)

'加载报表字段定义文件
Set props = objCRReport.Database.Tables(1).ConnectionProperties
For Each prop In props
If InStr(prop.Name, "Field Definition File") > 0 Then
prop.Value = App.Path & "\PjRpt.ttx" '字段定义文件 PjRpt.ttx
Exit For
End If
Next
Set props = Nothing

'清除报表中保持的数据
objCRReport.DiscardSavedData
objCRReport.EnableParameterPrompting = False '不进行报表参数提示
'赋给报表数据
objCRReport.Database.SetDataSource rst
'--------------------------------------------------

'进行报表显示外观设置
'--------------------------------------------------

objCRReport.LeftMargin = 260 '左边距
objCRReport.RightMargin = 10 '右边距

CRViewer91.EnableExportButton = True '导出按钮
' CRViewer91.EnableSelectExpertButton = True
' CRViewer91.DisplayGroupTree = False '不显示组树
' CRViewer91.EnableAnimationCtrl = False
' CRViewer91.EnableCloseButton = False
' CRViewer91.EnableGroupTree = False
' CRViewer91.EnableHelpButton = False
' CRViewer91.EnableRefreshButton = False
CRViewer91.EnableNavigationControls = True '显示总页数和下一页
' CRViewer91.EnablePopupMenu = False
' CRViewer91.EnableSearchControl = False
' CRViewer91.EnableSearchExpertButton = False '查找
' CRViewer91.EnableSelectExpertButton = False
' CRViewer91.DisplayTabs = False

CRViewer91.DisplayBackgroundEdge = False
CRViewer91.EnableAnimationCtrl = False
CRViewer91.EnableCloseButton = False
CRViewer91.EnableGroupTree = False
CRViewer91.EnableHelpButton = False
CRViewer91.EnableRefreshButton = False
CRViewer91.EnableSearchExpertButton = False
CRViewer91.EnableSelectExpertButton = False
'指定报表来源
CRViewer91.ReportSource = objCRReport
'显示报表
CRViewer91.ViewReport
Set rst = Nothing

End Sub

Private Sub Form_Resize()
On Error Resume Next
CRViewer91.Left = 200
CRViewer91.Width = Me.Width - 500
CRViewer91.Height = Me.Height
End Sub

cailin381x 2009-04-08
  • 打赏
  • 举报
回复
我也遇到这个问题 ,我是C#+sql,学习一下

1,215

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧