473,549 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change Crystal Report DATA TABLE not Database

OuTCasT
374 Contributor
I know how to change the database and sqlserver for a crystal report

Expand|Select|Wrap|Line Numbers
  1. Dim report As New ReportDocument
  2.         Dim connection As IConnectionInfo
  3.         Dim oldServerName As String = ".\SQLEXPRESS"
  4.         Dim oldDatabaseName As String = oldDatabaseName
  5.         Dim newServerName As String = newServerName
  6.         Dim newDatabaseName As String = newDatabaseName
  7.         Dim UserID As String = ""
  8.         Dim Password As String = ""
  9.  
  10.  
  11.         report.Load(Application.StartupPath + "\Reports\ValidationReport.rpt")
  12.         CrystalReportViewer1.ReportSource = report
  13.  
  14.         'Change the server name and database in main report
  15.         For Each connection In report.DataSourceConnections
  16.             report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  17.         Next
  18.         'Change the server name and database subreports
  19.         Dim subreport As ReportDocument
  20.         For Each subreport In report.Subreports
  21.             For Each connection In subreport.DataSourceConnections
  22.                 If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
  23.                    And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
  24.                     subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  25.                 End If
  26.             Next
  27.         Next
  28.         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.
Mar 6 '09 #1
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:

Expand|Select|Wrap|Line Numbers
  1. Dim crxTable As CRAXDRT.DatabaseTable
  2. For Each crxTable In Report.Database.Tables
  3.     crxTable.Location = Replace (crxTable.Location, "VS2010", "VS2009")
  4. Next
  5.  
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
Mar 9 '09 #2
OuTCasT
374 Contributor
Thanks i will give it a go later today.
The tablename will be stored in a variable so it can be changed whenever.
Mar 9 '09 #3
OuTCasT
374 Contributor
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....?
Mar 10 '09 #4
OuTCasT
374 Contributor
Sorry.....I had to add the Crystal Reports ActiveX Designer Run time Library before i could reference.

Thanks,
Mar 10 '09 #5
OuTCasT
374 Contributor
@QVeen72
Hi Veena

This is my code

Expand|Select|Wrap|Line Numbers
  1. Dim report As New ReportDocument
  2.         Dim connection As IConnectionInfo
  3.         Dim oldServerName As String = "DONOVANPC\SQLEXPRESS"
  4.         Dim oldDatabaseName As String = "PayDay10"
  5.         Dim newServerName As String = strOldServerName
  6.         Dim newDatabaseName As String = strCompanyName
  7.         Dim UserID As String = ""
  8.         Dim Password As String = ""
  9.  
  10.         Dim crxTable As CRAXDDRT.DatabaseTable
  11.  
  12.         report.Load(Application.StartupPath + "\Reports\ValidationReport.rpt")
  13.         CrystalReportViewer1.ReportSource = report
  14.  
  15.         For Each crxTable In report.Database.Tables
  16.             crxTable.Location = Replace(crxTable.Location, "IRPV2010", "IRPV2009")
  17.         Next
  18.         'Change the server name and database in main report
  19.         For Each connection In report.DataSourceConnections
  20.             report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  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
  32.         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 ?
Mar 10 '09 #6
OuTCasT
374 Contributor
Expand|Select|Wrap|Line Numbers
  1. Dim report As New ReportDocument
  2.         Dim connection As IConnectionInfo
  3.         Dim oldServerName As String = "DONOVANPC\SQLEXPRESS"
  4.         Dim oldDatabaseName As String = "PayDay10"
  5.         Dim newServerName As String = strOldServerName
  6.         Dim newDatabaseName As String = strCompanyName
  7.         Dim UserID As String = ""
  8.         Dim Password As String = ""
  9.  
  10.         'Dim crxTable As CRAXDDRT.DatabaseTable
  11.  
  12.         Dim crxTable As CrystalDecisions.CrystalReports.Engine.Table
  13.  
  14.         report.Load(Application.StartupPath + "\Reports\ValidationReport.rpt")
  15.         CrystalReportViewer1.ReportSource = report
  16.  
  17.         For Each crxTable In report.Database.Tables
  18.             crxTable.Location = Replace(crxTable.Location, "IRPV2010", "IRPV2010")
  19.         Next
  20.         'Change the server name and database in main report 
  21.         For Each connection In report.DataSourceConnections
  22.             report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  23.         Next
  24.         'Change the server name and database subreports 
  25.         Dim subreport As ReportDocument
  26.         For Each subreport In report.Subreports
  27.             For Each connection In subreport.DataSourceConnections
  28.                 If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
  29.                    And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
  30.                     subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection(newServerName, newDatabaseName, UserID, Password)
  31.                 End If
  32.             Next
  33.         Next
  34.         CrystalReportViewer1.RefreshReport()
Used this line instead

Expand|Select|Wrap|Line Numbers
  1. 'Dim crxTable As CRAXDDRT.DatabaseTable
  2.  
  3. Dim crxTable As CrystalDecisions.CrystalReports.Engine.Table
Now its changing the database tables.

Thanks Veena
Mar 10 '09 #7
OuTCasT
374 Contributor
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

Expand|Select|Wrap|Line Numbers
  1.  Dim crxTable As CrystalDecisions.CrystalReports.Engine.Table
  2.         For Each crxTable In report.Database.Tables
  3.             crxTable.Location = Replace(crxTable.Location, "IRP2010", table)
  4.         Next
  5.         Dim crxTable2 As CrystalDecisions.CrystalReports.Engine.Table
  6.         For Each crxTable2 In subreport.Database.Tables
  7.             crxTable2.Location = Replace(crxTable2.Location, "IRPD2010", table2)
  8.         Next
am i being stupid cause this doesnt work. lol
Mar 12 '09 #8

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

Similar topics

4
1130
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...
2
760
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. ...
2
1253
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...
3
6891
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)
3
2147
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...
7
34758
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...
7
11239
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...
0
1862
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"
1
1497
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...
0
7526
marktang
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...
0
7965
jinu1996
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...
1
7483
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...
0
7817
tracyyun
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...
0
6051
agi2029
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...
1
5375
isladogs
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...
0
3504
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...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
771
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.