473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Crystal Reports Change Datasource dynamically

OuTCasT
374 256MB
Hi I dont understand why this code does not change the Crystal Reports Datasource and Database at runtime.
I have used it before but for some reason it doesnt want to work.

Expand|Select|Wrap|Line Numbers
  1. Dim report As New CrystalDecisions.CrystalReports.Engine.ReportDocument
  2.         Dim connection As IConnectionInfo
  3.         Dim OldServerName As String = [OLD Servername]
  4.         Dim NewServerName As String = [NEW SERVERName]
  5.         Dim NewDatabaseName As String = [New DB]
  6.         Dim OldDatabaseName As String = [OLD DB]
  7.         Dim UserID As String = ""
  8.         Dim Password As String = ""
  9.  
  10.         report.Load(Application.StartupPath + "\Reports\SCBA_HISTORY_MAINTENANCE_REPORT.rpt")
  11.         'relac = "{SCBAMASK.SerialNo}=" & Chr(39) & (strEditSCBAMASKSERIAL) & Chr(39)
  12.         'report.DataDefinition.RecordSelectionFormula = relac
  13.         CrystalReportViewer1.ReportSource = report
  14.  
  15.         'Change the servername and database in main report
  16.         For Each connection In report.DataSourceConnections
  17.             report.DataSourceConnections(OldServerName, OldDatabaseName).SetConnection(NewServerName, NewDatabaseName, UserID, Password)
  18.  
  19.         Next
  20.         'Change the servername and database in subreports
  21.         For Each subreport In report.Subreports
  22.             For Each connection In subreport.datasourceconnections
  23.                 If (String.Compare(connection.ServerName, OldServerName, True) = 0 _
  24.                    And String.Compare(connection.DatabaseName, OldDatabaseName, True) = 0) Then
  25.                     subreport.DataSourceConnections(OldServerName, OldDatabaseName).SetConnection(NewServerName, NewDatabaseName, UserID, Password)
  26.                 End If
  27.             Next
  28.         Next
  29.         CrystalReportViewer1.RefreshReport()
  30.  
  31.         'Me.Close()
  32.  
  33.         'MsgBox(ex.Message)
  34.         'CrystalReportViewer1.PrintReport()
This is the screen i get on the test PC running Windows 7
But on my pc it changes perfectly.



Its like its not pulling through the Database Name
But when debugging it pulls through the databse name no problems.

Can anyone see something i dont.
Mar 3 '11 #1
0 1912

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

Similar topics

5
by: Ron | last post by:
I have a bunch of Crystal Reports (v9) published as WebServices and use a ReportViewer to display the reports on the ASPNET page. Everytime we move the reports from dev to production we have to...
4
by: touf | last post by:
hi, I'm using Crystal reports to generate a simple report in a VB.net windows application, I've defined all my stuffs (accessMDB,query, 2 parameters) in the report design, and it's working fine,...
5
by: Henry | last post by:
I am writing a Windows forms VB.Net/MS SQL application that utilizes Crystal Reports. I want to be able to dynamically set the report data source at run time. According to article...
1
by: Justin Bezanson | last post by:
I have got the following report running as described in my other post http://forums.asp.net/thread/1320780.aspx I would like to know how to change the generic column headers (column1,2,3...) to...
7
by: Jlo | last post by:
Hi, I have a c# winforms application. When I call the report file, it shows me all the records in the table. How can I make it to call only a particular range. i have the following code...
1
by: =?Utf-8?B?VGVycnk=?= | last post by:
I am brand new to using Crystal Reports and am trying to generate a report based on a custom object - in another project. I have a layered design, with all my business objects in a seperate...
0
by: jcunningham | last post by:
Hello. I am running Crystal Reports (CR) from within an Access DB. I need to be able to have CR point to the Access DB it resides in automatically. That is, the CR's reside in the database I...
1
by: bhappy | last post by:
Hai All, I want to create crystal reports dynamically, I don't know the columns i will take it from database at runtime, im getting all data into one dataset and im convrting dataset into xml...
8
by: Brock | last post by:
I am trying to populate a Crystal Report from data in my DataGrid. The reason for this is that I want the user to be able to change values without updating the database, but still have their report...
4
by: remya1000 | last post by:
I'm using VB.NET 2003 windows application. i'm trying to display Crystal Reports using CrystalReportViewer. Code i'm using to display "ZTab.rpt" in CrystalReportViewer when Form_Load ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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,...
0
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...

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.