By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

Crystal Reports

OuTCasT
100+
P: 374
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

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

Post your reply

Sign in to post your reply or Sign up for a free account.