Maybe this code can help you, I use it to run my reports on different db's
ofcourse the tablenames have to be the same.
hth Greetz Peter
add reference to CrystalDecision s.CrystalReport s.Engine.dll
Imports CrystalDecision s.CrystalReport s.Engine
Imports CrystalDecision s.Shared
Imports CrystalDecision s.ReportSource
Dim tblCurrent As Table
Dim crSubreportObje ct As SubreportObject
Dim subRepDoc As New ReportDocument
Dim crDatabase As CrystalDecision s.CrystalReport s.Engine.Databa se
Dim crTables As Tables
Dim crTable As Table
Dim crSection As Section
Dim crSections As Sections
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crLogOnInfo As TableLogOnInfo
Dim crpConnectionIn fo As New CrystalDecision s.Shared.Connec tionInfo
Dim crpTableLogOnIn fo As New CrystalDecision s.Shared.TableL ogOnInfo
Dim crReportDocumen t As New ReportDocument
crReportDocumen t.Load(psReport Name)
CrystalReportVi ewer1.ReportSou rce = crReportDocumen t
CrystalReportVi ewer1.Zoom(2)
'
' Aanpassen server voor hoofdrapport
'
With crpConnectionIn fo
.ServerName = "Yourserver "
.DatabaseName = "YourDataBa se"
End With
'set this if you don't work with integrated security
'crpConnectionI nfo.UserID = "user"
'crpConnectionI nfo.Password = "password"
For Each tblCurrent In crReportDocumen t.Database.Tabl es
crpTableLogOnIn fo = tblCurrent.LogO nInfo
crpTableLogOnIn fo.ConnectionIn fo = crpConnectionIn fo
tblCurrent.Appl yLogOnInfo(crpT ableLogOnInfo)
Next
'Set the sections collection with report sections
crSections = crReportDocumen t.ReportDefinit ion.Sections
For Each crSection In crSections
crReportObjects = crSection.Repor tObjects
For Each crReportObject In crReportObjects
If crReportObject. Kind = ReportObjectKin d.SubreportObje ct
Then
'If you find a subreport, typecast the reportobject to a
subreport object
crSubreportObje ct = CType(crReportO bject,
SubreportObject )
'Open the subreport
subRepDoc =
crSubreportObje ct.OpenSubrepor t(crSubreportOb ject.SubreportN ame)
crDatabase = subRepDoc.Datab ase
crTables = crDatabase.Tabl es
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object then
apply the
'logoninfo to the subreport
For Each crTable In crTables
With crpConnectionIn fo
.ServerName = "YourServer "
.DatabaseName = "YourDataBa se"
End With
crLogOnInfo = crTable.LogOnIn fo
crLogOnInfo.Con nectionInfo = crpConnectionIn fo
crTable.ApplyLo gOnInfo(crLogOn Info)
Next
End If
Next
Next
"Jasper Jones" <ja*******@gmai l.com> schreef in bericht
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi, I've designed several Crystal Reports using the built in wizard.
They point to my database as HQ which is called "Thom". There is a
database called Sales on Thom which all the reports point to and get
their results from.
I'm ready to compile my program to give to the users at a different
site. They have a database server there called "Sidney" which had a
copy of the same "Sales" database on there. Is there a way I can
change the database of my report when I load it each time, it looks
like I'd have to go through each individual report and change the
database settings which would be very time consuming as I will be using
quite a few database servers with this program. I'd like to just
specify a database or dataset in the code.
This is how I call the report:
Dim Cr As New crRefunds
CrystalReportVi ewer1.ReportSou rce = Cr
it would be ideal if I could put a line in above, something like
cr.database = "Sidney". Is anything like this possible? If not what
is the best way to switch the database?
Any help or pointers will be greatly appreciated as I'm really stuck
with this one.