2013-01-15 11 views
6
Imports CrystalDecisions.CrystalReports.Engine 
Imports CrystalDecisions.Shared 
Imports CrystalDecisions.Web 
Imports CrystalDecisions.ReportSource 
Imports CrystalDecisions.CrystalReports 

Imports System.IO 
Imports System.Net 
Imports System.Net.Mail 

Public Class Form1 

Dim cryRpt As New ReportDocument 

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    cryRpt.Load("C:\Documents and Settings\Prs1\My Documents\Visual Studio 2008\Projects\myCR\myCR\cr.rpt") 
    CrystalReportViewer1.ReportSource = cryRpt 

    CrystalReportViewer1.Refresh() 

    Try 
     Dim CrExportOptions As ExportOptions 
     Dim CrDiskFileDestinationOptions As New _ 
     DiskFileDestinationOptions() 
     Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions() 
     CrDiskFileDestinationOptions.DiskFileName = _ 
            "C:\crystalExport.pdf" 
     CrExportOptions = cryRpt.ExportOptions 
     With CrExportOptions 
      .ExportDestinationType = ExportDestinationType.DiskFile 
      .ExportFormatType = ExportFormatType.PortableDocFormat 
      .DestinationOptions = CrDiskFileDestinationOptions 
      .FormatOptions = CrFormatTypeOptions 
     End With 
     cryRpt.Export() 
    Catch ex As Exception 
     MsgBox(ex.ToString) 
    End Try 

End Sub 

End ClassWie programmatisch

Ich habe versucht, den obigen Code Crystal Report als PDF in VB.NET zu exportieren. Ich habe ein Windows Form und eine einzelne Crystal Report-Datei (cr.rpt) in meinem Projektordner. Ich verwende Oracle 10G als Datenbank. Aber ich bekomme einen Fehler, der "Logon Failed" sagt. ([Fehlerbeschreibung] Bild: http://pho.to/Zv6t)

Pls helfen.

+0

Diese liegt wahrscheinlich daran, dass Sie dem Bericht nicht mitgeteilt haben, welche Anmeldeinformationen für die Verbindung zur Datenbank erforderlich sind. Sie legen sie für das Design des Berichts als Entwurf fest, aber Sie müssen den Bericht zur Laufzeit erneut melden. –

+0

@ Ciarán Können Sie mir sagen, wo ich die Anmeldedaten einstellen soll? Ich bin neu in VB.NET und Crystal Reports. Und auch jedes Codebeispiel, das in Runtime gesetzt werden soll? –

+0

Danke euch. Gefunden die Lösung von [hier] (http://stackoverflow.com/questions/12486925/crystal-reports-how-to-set-database-credentials) –

Antwort

1

schließlich die Lösung von here

Die einzige Sache ist, finde ich brauche Datenbank-Anmeldeinformationen zur Laufzeit festgelegt für den Crystal Report funktionieren.

0

Dieses übliche Problem tritt nur mit der älteren Version von CrystalReports Anrufer von VB zu .Net Welt.

Nichts zu sorgen. Bitte verwenden Sie wie folgt .........

connectionInfo.DatabaseName = "MahendrenDataBase" 

connectionInfo.ServerName ="SystemDSN";//Create a system dsn. 

connectionInfo.UserID = "UID"; 

connectionInfo.Password="Pwd" 
0

Importe CrystalDecisions.CrystalReports.Engine

Importe CrystalDecisions.Shared

Dim rpt As New RptCashbill

 ''''''fill Report data'''''' 
    CType(rpt,ReportDocument).ExportToDisk(ExportFormatType.PortableDocFormat,"C:/Report.pdf")