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 10096 QVeen72 1,445
Recognized Expert Top Contributor
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.MyTa bleName
It need to be changed to VS2009.dbo.MyTa bleName
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.databas etable
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 'CrystalDecisio ns.CrystalRepor ts.Engine.Table ' to type 'CRAXDDRT.Datab aseTable'.
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 option. The problem is that these
database settings seem to get compiled into the report, so when we take the
application to our client it won't...
|
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 know.
This is a common problem, but nobody seems to have an answer for it.
CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed.
...
|
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. Throughout the project I'm working on, I
often find I need a temporary table displayed in a report, something
that I cannot seem to do. Since temporary...
|
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 populated so it
has to be a very basic binding issue.
To bind the report object to dataset I called the SetDataSource method
of Report object...
| |
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 data from ADO.NET Datasets that are pre-populated by
other modules of the application.
What I need to do is to use these datasets as the datasources...
|
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 the the reports "integrated security" from TRUE to
FALSE via the "Set Location" dialog in the report designer with no
success. It is not intuitive (at...
|
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:
...
ReportTemp.Load(_reportname)
For Each table In ReportTemp.Database.Tables
logoninfo = table.LogOnInfo
With logoninfo.ConnectionInfo
.ServerName = "Server"
|
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 with Visual Studio.
It seems like it should be pretty straight forward, but no matter what I do I can't get my reports to actually show data. Here's...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |