Crystal Reports具有两个不同的数据库

时间:2018-03-14 21:35:52

标签: vb.net crystal-reports

我在Crystal Report中做了一个报告,它从两个独立的数据库中提取数据。它们都在同一台服务器上。当我尝试从我的VB应用程序运行报告时,它说无法找到该表。我很确定这个错误来自第二个数据库,因为如果我从报告中删除一个数据库就行了。

我的问题是,如何让VB或Crystal看到第二个数据库?

1 个答案:

答案 0 :(得分:1)

您可以使用应用程序内的两个数据库创建数据集,并将数据集应用于晶体数据源,而不是连接到两个数据库。

例如:

Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As DataSet = New DataSet()
Dim obj As reports = New reports()
Dim crconnectioninfo As ConnectionInfo = New ConnectionInfo()
Dim crtablelogoninfos As TableLogOnInfos = New TableLogOnInfos()
Dim crtablelogoninfo As TableLogOnInfo = New TableLogOnInfo()
Dim CrTables As Tables
Try
    If _report = "ISR" Then
        crconnectioninfo.ServerName = AquaInvoice.Properties.Settings.[Default].dsn_name
        crconnectioninfo.DatabaseName = AquaInvoice.Properties.Settings.[Default].databaseclient
        crconnectioninfo.UserID = AquaInvoice.Properties.Settings.[Default].db_user
        crconnectioninfo.Password = AquaInvoice.Properties.Settings.[Default].db_password

        'Set report path
        Dim AppPath As String = Application.StartupPath & "\Reports\rptInvoiceSummary.rpt"
        'load report
        reportDocument1.Load(AppPath)

       'Retrieve data to Dataset from the database. Here you can access two databases and create one dataset in you Data Layer
        ds = obj.InvoiceSearchBox(dtpStart.Value.Date, dtpEnd.Value.Date)

        'Set report source
        reportDocument1.Database.Tables(0).SetDataSource(ds.Tables(0))
        reportDocument1.Database.Tables(1).SetDataSource(ds.Tables(1))
        'Set parameter values
        reportDocument1.SetParameterValue("Start", dtpStart.Value.Date)
        reportDocument1.SetParameterValue("End", dtpEnd.Value.Date)
        'set viewer
        crvDateRangeReports.ReportSource = reportDocument1
        crvDateRangeReports.Refresh()
    End If
Catch ex As Exception
    Throw New Exception("Report load faild!", ex)
End Try
End Sub
'This code originally c# and converted to vb using online code converter