Connecting Tech Pros Worldwide Forums | Help | Site Map

Crystal reports

OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 355
#1: Jun 30 '08
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.

Expand|Select|Wrap|Line Numbers
  1. Dim report As New ReportDocument
  2.         Dim connection As IConnectionInfo
  3.         Dim oldServerName As String = ""
  4.         Dim oldDatabaseName As String = ""
  5.         Dim newServerName As String = TextBox1.Text
  6.         Dim newDatabaseName As String = "dude"
  7.         Dim UserID As String = ""
  8.         Dim Password As String = ""
  9.  
  10.  
  11.         report.Load("C:\report2.rpt")
  12.         CrystalReportViewer1.ReportSource = report
  13.  
  14.         'Change the server name and database in main report
  15.         For Each connection In report.DataSourceConnections
  16.             If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
  17.                And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
  18.                 'SetConnection can also be used to set new logon and new database table
  19.                 report.DataSourceConnections(oldDatabaseName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  20.             End If
  21.         Next
  22.         'Change the server name and database subreports
  23.         Dim subreport As ReportDocument
  24.         For Each subreport In report.Subreports
  25.             For Each connection In subreport.DataSourceConnections
  26.                 If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
  27.                    And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
  28.                     subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  29.                 End If
  30.             Next
  31.         Next

Newbie
 
Join Date: Jul 2008
Posts: 1
#2: Jul 21 '08

re: Crystal reports


I did something like this:

private report2 As ReportDocument

in load:

report2 = New ReportDocument
report2.Load("report1.rpt")
report2.SetDatabaseLogon(UserName, UserPassword)

report2.Database.Tables(0).SetDataSource(datatable 1)
report2.Refresh()
cristalViewer1.ReportSource = report2
Reply