Crystal reports

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

    Crystal reports

    i have a payroll program that can start new companies, a company has its own database. they will always be the same tables etc inside all the databases/companies.

    now i have done a report in crystal reports. now i want to use jst that report for all the companies that will be created.
    I have changed the servername and databasename at runtime but it still brings back the information from the company that i designed the report on....
    is there something that im missing.

    [CODE=visualbasi c]Dim report As New ReportDocument
    Dim connection As IConnectionInfo
    Dim oldServerName As String = ""
    Dim oldDatabaseName As String = ""
    Dim newServerName As String = TextBox1.Text
    Dim newDatabaseName As String = "dude"
    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[/CODE]
  • asmvax
    New Member
    • Jul 2008
    • 1

    #2
    I did something like this:

    private report2 As ReportDocument

    in load:

    report2 = New ReportDocument
    report2.Load("r eport1.rpt")
    report2.SetData baseLogon(UserN ame, UserPassword)

    report2.Databas e.Tables(0).Set DataSource(data table1)
    report2.Refresh ()
    cristalViewer1. ReportSource = report2

    Comment

    Working...