Re: Crystal Reports anmelden an der Datenbank
- From: "Thomas Wenning" <nospam.mittsommernachtslauf@xxxxxx>
- Date: Mon, 6 Jun 2005 15:47:07 +0100
"sascha salentin" <saschasalentin@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im
Newsbeitrag news:54813DF5-9A0D-403C-B666-B0588F35C0CE@xxxxxxxxxxxxxxxx
> Hi,
> ich habe nach Anleitung von Seagate CrystalReport-Dokumente eingebunden.
> Funktioniert auch ganz gut, ich habe nur ein Problem, das Crystal-Dokument
> möchte eine Datenbankanmeldung haben, wie übergebe ich diese von vb aus??
>
> Bisheriger Code:
>
> Dim oReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
> oReport.Load(ProgramPath & "\RPT\" & Rep)
>
> Dim LogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
> Dim Table As CrystalDecisions.CrystalReports.Engine.Table
> For Each Table In oReport.Database.Tables
> 'Get the TableLogOnInfo object
> LogonInfo = Table.LogOnInfo
> 'Set the server name, database name user ID, and password.
> LogonInfo.ConnectionInfo.ServerName = "localhost"
> LogonInfo.ConnectionInfo.DatabaseName = "SQL-DB"
> LogonInfo.ConnectionInfo.UserID = SQLDataBaseUser
> LogonInfo.ConnectionInfo.Password = SQLDataBasePassword
> 'Apply the connection information to the table.
> Table.ApplyLogOnInfo(LogonInfo)
> Next Table
>
>
> Dim paraValue As New
CrystalDecisions.Shared.ParameterDiscreteValue
> paraValue.Value = DatumVon
> Dim currValue As CrystalDecisions.Shared.ParameterValues
> currValue =
> oReport.DataDefinition.ParameterFields("DatumVon").CurrentValues
> currValue.Add(paraValue)
>
>
oReport.DataDefinition.ParameterFields("DatumVon").ApplyCurrentValues(currVa
lue)
>
> paraValue.Value = DatumBis
> currValue =
> oReport.DataDefinition.ParameterFields("DatumBis").CurrentValues
> currValue.Add(paraValue)
>
>
oReport.DataDefinition.ParameterFields("DatumBis").ApplyCurrentValues(currVa
lue)
>
>
> myCrystalReportViewer.ReportSource = oReport
> myCrystalReportViewer.Zoom(75)
>
> Gruß sascha
>
Hallo Sascha,
da du dein Problem nicht über ein Dataset lösen möchtest, empfehle ich eine
InitProc wie folgt(Gilt auch für Subreports!):
Private Sub ReportInit(ByVal blRefreshLocation As Boolean)
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crReportDocument As ReportDocument
Dim crSubreportDocument As ReportDocument
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectioninfo As ConnectionInfo
Dim myArrayList As ArrayList = New ArrayList
'declare an instance of the report and the connectionInfo object
crReportDocument = New ReportDocument
crConnectioninfo = New ConnectionInfo
crReportDocument.Load(/*my Reportname + Location*/)
'pass the necessary parameters to the connectionInfo object
With crConnectioninfo
.ServerName = /* my SQL DB ServerName string*/
.DatabaseName = /* my SQL DataBaseName string*/
End With
'set up the database and tables objects to refer to the current
report
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
'loop through all the tables and pass in the connection info
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
If blRefreshLocation Then
crTable.Location = mstrDataBaseName & ".dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
End If
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
'set the crSections object to the current report's sections
crSections = crReportDocument.ReportDefinition.Sections
'loop through all the sections to find all the report objects
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
'loop through all the report objects to find all the subreports
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject
Then
'you will need to typecast the reportobject to a
subreport
'object once you find it
crSubreportObject = CType(crReportObject,
SubreportObject)
'open the subreport object
crSubreportDocument =
crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
'set the database and tables objects to work with the
subreport
crDatabase = crSubreportDocument.Database
crTables = crDatabase.Tables
'loop through all the tables in the subreport and
'set up the connection info and apply it to the tables
For Each crTable In crTables
With crConnectioninfo
.ServerName = mstrDBServerName
End With
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
If blRefreshLocation Then
crTable.Location = mstrDataBaseName & ".dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
End If
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
End If
Next
Next
crystalReportViewer.ReportSource = crReportDocument
End Sub
.
- References:
- Crystal Reports anmelden an der Datenbank
- From: sascha salentin
- Crystal Reports anmelden an der Datenbank
- Prev by Date: Re: String nach Unicode wandeln
- Next by Date: VB 8 und VB 6 zusammen installieren
- Previous by thread: Crystal Reports anmelden an der Datenbank
- Next by thread: E-Mail landet im Spamfilter
- Index(es):
Relevant Pages
|