Sich dynamisch verändernde MySQL-Verbindungszeichenfolge zu Crystal Reports

Ich bin mit CrystalReportViewer und CrystalReportSource zu laden und anzeigen ein .die rpt-Datei in meine Anwendung.

Die situation, die ich habe, ist diese:

Sagen eine person erstellt ein Crystal-Reports-berichten außerhalb meiner Anwendung und legen Sie die datasource für die Datenbank. Dann nutze ich das .die rpt-Datei in meine Anwendung, aber ich brauche es zu binden, um eine andere Datenbank (identisch mit dem original im Hinblick auf die Tabellen-Struktur-und Spalten-Namen, aber mit einer anderen connection string und user-name und Passwort).

Wie mache ich das in VB.NET code?

Derzeit lade ich den Bericht mit:

Public Function SetReportSource(ByVal RptFile As String) As ReportDocument

    Try
        Dim crtableLogoninfo As New TableLogOnInfo()
        Dim crConnectionInfo As New ConnectionInfo()
        Dim CrTables As Tables
        Dim CrTable As Table

        If System.IO.File.Exists(RptFile) Then
            Dim crReportDocument As New ReportDocument()
            crReportDocument.Load(RptFile)

            With crConnectionInfo
                .ServerName = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;Port=3306;UID=root;"
                .DatabaseName = gDatabaseName
                .UserID = gServerUser
                .Password = gServerPassword
            End With

            CrTables = crReportDocument.Database.Tables
            For Each CrTable In CrTables
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
                CrTable.LogOnInfo.ConnectionInfo.ServerName = crConnectionInfo.ServerName
                CrTable.LogOnInfo.ConnectionInfo.DatabaseName = crConnectionInfo.DatabaseName
                CrTable.LogOnInfo.ConnectionInfo.UserID = crConnectionInfo.UserID
                CrTable.LogOnInfo.ConnectionInfo.Password = crConnectionInfo.Password
                'Apply the schema name to the table's location
                CrTable.Location = gDatabaseName & "." & CrTable.Location
            Next

            crReportDocument.VerifyDatabase()
            SetReportSource = crReportDocument
        Else
            MsgBox("Report file not found...", MsgBoxStyle.Critical, proTitleMsg)
        End If
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show("Error Found..." & vbCrLf & "Error No : " & Err.Number & vbCrLf & "Description :" & Err.Description & vbCrLf & vbCrLf & "Line no : " & Err.Erl & vbCrLf & "Procedure name : SetReportSource" & vbCrLf & "Module name : GeneralFunctions", proTitleMsg)
    End Try

End Function

InformationsquelleAutor Kannan | 2011-06-02

Schreibe einen Kommentar