Crystal Reports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    Crystal Reports

    Hi all.
    I did a report in Crystal for a payroll program. they start a company which is a database.
    now can i use 1 report for all the companies because all the companies/database will have exactly the same tables and heading etc.
    how would i change the databasename for the report so that i can get the data from the different databases.... i did it like this but it aint working

    [CODE=visual basic]Private Sub Report()
    Dim report As New ReportDocument
    Dim connection As IConnectionInfo
    Dim oldServerName As String = TextBox1.Text
    Dim oldDatabaseName As String = txtCompanyName. Text
    Dim newServerName As String = TextBox1.Text
    Dim newDatabaseName As String = txtCompanyName. Text
    Dim UserID As String = ""
    Dim Password As String = ""


    report.Load("C: \report2.rpt")
    CrystalReportVi ewer1.ReportSou rce = report

    'Change the server name and database in main report
    For Each connection In report.DataSour ceConnections
    If (String.Compare (connection.Ser verName, oldServerName, True) = 0 _
    And String.Compare( connection.Data baseName, oldDatabaseName , True) = 0) Then
    'SetConnection can also be used to set new logon and new database table
    report.DataSour ceConnections(o ldDatabaseName, oldDatabaseName ).SetConnection (newServerName, newDatabaseName , UserID, Password)
    End If
    Next
    'Change the server name and database subreports
    Dim subreport As ReportDocument
    For Each subreport In report.Subrepor ts
    For Each connection In subreport.DataS ourceConnection s
    If (String.Compare (connection.Ser verName, oldServerName, True) = 0 _
    And String.Compare( connection.Data baseName, oldDatabaseName , True) = 0) Then
    subreport.DataS ourceConnection s(oldServerName , oldDatabaseName ).SetConnection (newServerName, newDatabaseName , UserID, Password)
    End If
    Next
    Next
    End Sub[/CODE]
Working...