Change Crystal Report DATA TABLE not Database  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| |
I know how to change the database and sqlserver for a crystal report - Dim report As New ReportDocument
-
Dim connection As IConnectionInfo
-
Dim oldServerName As String = ".\SQLEXPRESS"
-
Dim oldDatabaseName As String = oldDatabaseName
-
Dim newServerName As String = newServerName
-
Dim newDatabaseName As String = newDatabaseName
-
Dim UserID As String = ""
-
Dim Password As String = ""
-
-
-
report.Load(Application.StartupPath + "\Reports\ValidationReport.rpt")
-
CrystalReportViewer1.ReportSource = report
-
-
'Change the server name and database in main report
-
For Each connection In report.DataSourceConnections
-
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
-
Next
-
'Change the server name and database subreports
-
Dim subreport As ReportDocument
-
For Each subreport In report.Subreports
-
For Each connection In subreport.DataSourceConnections
-
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
-
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
-
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
-
End If
-
Next
-
Next
-
CrystalReportViewer1.RefreshReport()
Now in the application the report must be able to change database tables according to the year that we are in. for instance i have a table VS2009 and VS2010 and i want the data from the VS2009 table instead of the VS2010 data. how do i change the table for the report. Both tables are identical.
|  | Moderator | | Join Date: Oct 2006 Location: Bangalore
Posts: 1,385
| | | re: Change Crystal Report DATA TABLE not Database
Hi,
If you have designed the Report on database :VS2010, You have to Change the Location at runtime.. Use this code: -
Dim crxTable As CRAXDRT.DatabaseTable
-
For Each crxTable In Report.Database.Tables
-
crxTable.Location = Replace (crxTable.Location, "VS2010", "VS2009")
-
Next
-
Say, Location will be showing : VS2010.dbo.MyTableName
It need to be changed to VS2009.dbo.MyTableName
It has to be done for all tables in the report, as well as all Tables in sub report
Regards
Veena
|  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| | | re: Change Crystal Report DATA TABLE not Database
Thanks i will give it a go later today.
The tablename will be stored in a variable so it can be changed whenever.
|  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| | | re: Change Crystal Report DATA TABLE not Database
Hi. sorry man. i dont knw where to integrate your piece of code into my project.
Dim crxD as CRAXDRT.databasetable
what does CRAXDRT represent....?
|  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| | | re: Change Crystal Report DATA TABLE not Database
Sorry.....I had to add the Crystal Reports ActiveX Designer Run time Library before i could reference.
Thanks,
|  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| | | re: Change Crystal Report DATA TABLE not Database Quote:
Originally Posted by QVeen72 Hi,
If you have designed the Report on database :VS2010, You have to Change the Location at runtime.. Use this code: -
Dim crxTable As CRAXDRT.DatabaseTable
-
For Each crxTable In Report.Database.Tables
-
crxTable.Location = Replace (crxTable.Location, "VS2010", "VS2009")
-
Next
-
Say, Location will be showing : VS2010.dbo.MyTableName
It need to be changed to VS2009.dbo.MyTableName
It has to be done for all tables in the report, as well as all Tables in sub report
Regards
Veena Hi Veena
This is my code - Dim report As New ReportDocument
-
Dim connection As IConnectionInfo
-
Dim oldServerName As String = "DONOVANPC\SQLEXPRESS"
-
Dim oldDatabaseName As String = "PayDay10"
-
Dim newServerName As String = strOldServerName
-
Dim newDatabaseName As String = strCompanyName
-
Dim UserID As String = ""
-
Dim Password As String = ""
-
-
Dim crxTable As CRAXDDRT.DatabaseTable
-
-
report.Load(Application.StartupPath + "\Reports\ValidationReport.rpt")
-
CrystalReportViewer1.ReportSource = report
-
-
For Each crxTable In report.Database.Tables
-
crxTable.Location = Replace(crxTable.Location, "IRPV2010", "IRPV2009")
-
Next
-
'Change the server name and database in main report
-
For Each connection In report.DataSourceConnections
-
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
-
Next
-
'Change the server name and database subreports
-
Dim subreport As ReportDocument
-
For Each subreport In report.Subreports
-
For Each connection In subreport.DataSourceConnections
-
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
-
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
-
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
-
End If
-
Next
-
Next
-
CrystalReportViewer1.RefreshReport()
When i run the the app it gives me this error Quote:
Unable to cast object of type 'CrystalDecisions.CrystalReports.Engine.Table' to type 'CRAXDDRT.DatabaseTable'.
Can u help ?
|  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| | | re: Change Crystal Report DATA TABLE not Database - Dim report As New ReportDocument
-
Dim connection As IConnectionInfo
-
Dim oldServerName As String = "DONOVANPC\SQLEXPRESS"
-
Dim oldDatabaseName As String = "PayDay10"
-
Dim newServerName As String = strOldServerName
-
Dim newDatabaseName As String = strCompanyName
-
Dim UserID As String = ""
-
Dim Password As String = ""
-
-
'Dim crxTable As CRAXDDRT.DatabaseTable
-
-
Dim crxTable As CrystalDecisions.CrystalReports.Engine.Table
-
-
report.Load(Application.StartupPath + "\Reports\ValidationReport.rpt")
-
CrystalReportViewer1.ReportSource = report
-
-
For Each crxTable In report.Database.Tables
-
crxTable.Location = Replace(crxTable.Location, "IRPV2010", "IRPV2010")
-
Next
-
'Change the server name and database in main report
-
For Each connection In report.DataSourceConnections
-
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
-
Next
-
'Change the server name and database subreports
-
Dim subreport As ReportDocument
-
For Each subreport In report.Subreports
-
For Each connection In subreport.DataSourceConnections
-
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
-
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
-
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
-
End If
-
Next
-
Next
-
CrystalReportViewer1.RefreshReport()
Used this line instead - 'Dim crxTable As CRAXDDRT.DatabaseTable
-
-
Dim crxTable As CrystalDecisions.CrystalReports.Engine.Table
Now its changing the database tables.
Thanks Veena
|  | Needs Regular Fix | | Join Date: Jan 2008 Location: South Africa
Posts: 353
| | | re: Change Crystal Report DATA TABLE not Database
Everthing is working 100%
Now ive come across that i need to change the tables for my subreports in the report....
i have 2 tables for the report Main report : IRP2010 and the subreport IRPD2010
what i did was - Dim crxTable As CrystalDecisions.CrystalReports.Engine.Table
-
For Each crxTable In report.Database.Tables
-
crxTable.Location = Replace(crxTable.Location, "IRP2010", table)
-
Next
-
Dim crxTable2 As CrystalDecisions.CrystalReports.Engine.Table
-
For Each crxTable2 In subreport.Database.Tables
-
crxTable2.Location = Replace(crxTable2.Location, "IRPD2010", table2)
-
Next
am i being stupid cause this doesnt work. lol
|  | Similar Visual Basic 4 / 5 / 6 bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|