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.
7 10080
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
Thanks i will give it a go later today.
The tablename will be stored in a variable so it can be changed whenever.
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....?
Sorry.....I had to add the Crystal Reports ActiveX Designer Run time Library before i could reference.
Thanks,
@QVeen72
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
Unable to cast object of type 'CrystalDecisions.CrystalReports.Engine.Table' to type 'CRAXDDRT.DatabaseTable'.
Can u help ?
- 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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Grant Stanley |
last post by:
I'm developing an application in VS.Net 2003 using C#, which uses Crystal
Reports.
When creating each report, crystal asks where the database to use is, so I
specify our SQL server using the ADO...
|
by: Tim Burda |
last post by:
I posted this in another forum, but I'm adding it here to for more
exposure.I am using Visual Studio 2003 and trying to get Crystal
Reports to produce output. If you have any ideas, please let me...
|
by: airkart |
last post by:
Hello,
I've scoured groups and the web, and haven't found a question like mine
answered.
I'm using Visual Studio 2003 with the Crystal Reports it comes bundled
with and SQL Server 2000....
|
by: Gheaci Maschl |
last post by:
Hi all!
I would like to have your opinion about my problem and my proposal how
to solve it:
Ingredients:
- BTriev database
- Crystal Reports
- maybe MS Access
- Liinos6 (small ERP software)
|
by: Khurram |
last post by:
Hi,
I am trying to use Crystal Reports with ASP.NET. I created a dataset
and tried to display it in the report but nothing came up. I did not
get an exception either. I know that the dataset is...
|
by: TJoker .NET |
last post by:
I'm developing an VB.NET Windows Forms application that uses CR for VS.NET
(original version shipped with VS.NET 2002 - my VS.NET has the latest SP
installed, no SPs for CR).
My reports get their...
|
by: Henry |
last post by:
I am writing a Windows forms VB.Net/MS SQL application via VS 2003 that
utilizes Crystal Reports. I want to be able to dynamically set the
report data source at run time.
I'm trying to change...
|
by: Ray |
last post by:
Dear all,
Now I am using the report document in vb.net to call the crystal report
and I will set the database information in the report document. The code is
as follow:
......
|
by: narpet |
last post by:
Hello all...
I have a C# forms application that I am developing using MS Visual Studio 2005. I am trying to add some Crystal Reports to this application using the built in Crystal Reports tools...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |