我用水晶报表 开发 报表
在 VB中调用, 请问 怎么动态设定数据源
因为 VB中的数据源 是变化的
而 用Crystal Reports 开发时 采用了固定的数据库 加入相关的域。[email protected]

解决方案 »

  1.   

    我也碰到了这个问题,花费了不少时间,解决方法如下:1.数据库的动态连接如下
    Public crwReport As CRAXDRT.Report
    Private Const OracleDll = "crdb_oracle.dll"
    Private Function LogOn(ByVal LsSql As String) As Boolean
        Dim LsUser    As String '用户
        Dim LsPwd     As String '密码
        Dim LsSrv     As String 'db
        Dim LoDBTable As CRAXDRT.DatabaseTable    Screen.MousePointer = vbHourglass
        For Each LoDBTable In crwReport.Database.Tables
            If LoDBTable.DllName <> OracleDll Then
                LoDBTable.DllName = OracleDll
            End If
            With LoDBTable.ConnectionProperties
                .DeleteAll
                .Add "Server", LsSrv
                .Add "User ID", LsUser
                .Add "Password", LsPwd
            End With
        Next
    2.将水晶报表中的数据库连接中的[现在数据库连接项]logoff掉,这样才能在vb代码中设置数据库,
    否则数据库将被固定掉.如果解决不了的话,联系地址 [email protected]
      

  2.   

    Option Explicit
    Public adoPrimaryRS1 As New Recordset
    Public adoPrimaryRS2 As New Recordset
    Public adoPrimaryRS3 As New Recordset
    Public adoPrimaryRS4 As New Recordset
    Public adoPrimaryRS5 As New Recordset
    Public adoPrimaryRS6 As New RecordsetDim CPProperty As CRAXDRT.ConnectionProperty
    Dim DBTable As CRAXDRT.DatabaseTableDim m_report As CRAXDRT.Report
    Dim m_application As CRAXDRT.Application
    Private Sub CRViewer91_PrintButtonClicked(UseDefault As Boolean)
        m_report.PrinterSetup Me.hWnd
    End Sub
    Private Sub Form_Load()
    On Error Resume NextSet m_application = New CRAXDRT.Application
    Set m_report = m_application.OpenReport(App.Path + "\AR报表\c生产单.rpt")m_report.PaperOrientation = crLandscape
    m_report.DiscardSavedData
    m_report.Database.SetDataSource adoPrimaryRS1, 3, 1       '用户单位信息表
    m_report.Database.SetDataSource adoPrimaryRS2, 3, 2       '基本信息
    m_report.Database.SetDataSource adoPrimaryRS3, 3, 3       '工种
    m_report.Database.SetDataSource adoPrimaryRS4, 3, 4       '物品
    m_report.Database.SetDataSource adoPrimaryRS5, 3, 5       '项目
    m_report.Database.SetDataSource adoPrimaryRS6, 3, 6       '车间名称
    Screen.MousePointer = vbHourglass
    CRViewer91.ReportSource = m_report
    CRViewer91.ViewReport
    Screen.MousePointer = vbDefaultIf idDisplayMode = 1 Then
        CRViewer91.Zoom (75)
    Else
        CRViewer91.Zoom (50)
    End If
    End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)Set adoPrimaryRS1 = Nothing
    Set adoPrimaryRS2 = Nothing
    Set adoPrimaryRS3 = Nothing
    Set adoPrimaryRS4 = Nothing
    Set adoPrimaryRS5 = Nothing
    Set adoPrimaryRS6 = NothingSet CPProperty = Nothing
    Set DBTable = Nothing
    Set m_report = Nothing
    End SubPrivate Sub Form_Resize()
    CRViewer91.Top = 0
    CRViewer91.Left = 100
    CRViewer91.Height = ScaleHeight
    CRViewer91.Width = ScaleWidthEnd Sub
      

  3.   

    两位大侠你们的源代码让我总算对代码编程有个初步的了解,但你们可以告诉我CRAXDRT对象到底是什么吗?怎么在我机子上是CRAXDDRT而不是CRAXDRT,还有m_report.Database.SetDataSource adoPrimaryRS1, 3, 1       表示什么啊?打印的字段还是??????
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢
      

  4.   

    你用的是水晶报表9.2吧,我想9.2是CRAXDDRT类,8.5是CRAXDRT类
      

  5.   

    哥哥,我今天弄了好久都没弄出来,帮帮我吧
    http://expert.csdn.net/Expert/topic/2810/2810291.xml?temp=.5317346
      

  6.   

    PS:水晶报表9.2的Craxddrt和Craxdrt兩個都有夥計!!
    Craxdrt9.dll和Craxddrt9.dll在C:\winnt\Crystal\目錄下
      

  7.   

    在用水晶报表保存为.rpt时一定要把<<与数据一起保存>>选项去掉,,否则不能动态改变其数据.