2013-01-15 30 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 ClassLàm thế nào để programatically xuất báo cáo tinh thể dưới dạng PDF trong VB.NET

Tôi đã thử các mã trên. Tôi có một Windows Form và một tập tin báo cáo Crystal (cr.rpt) trong thư mục dự án của tôi. Tôi đang sử dụng Oracle 10G làm cơ sở dữ liệu. Nhưng tôi nhận được thông báo lỗi "Đăng nhập không thành công". ([Mô tả lỗi] Hình ảnh: http://pho.to/Zv6t)

Xin giúp đỡ.

+0

này có lẽ vì bạn chưa báo cáo về các thông tin đăng nhập để kết nối với cơ sở dữ liệu. Bạn đặt chúng ở thiết kế để thiết kế báo cáo, nhưng bạn cần phải báo cáo lại cho chúng vào thời gian chạy. –

+0

@ Ciarán Bạn có thể cho tôi biết nơi đặt thông tin đăng nhập không? Tôi mới dùng VB.NET và Crystal Reports. Và cũng có bất kỳ ví dụ mã nào để đặt trong Thời gian chạy không? –

+0

Cảm ơn các bạn. Tìm thấy giải pháp từ [đây] (http://stackoverflow.com/questions/12486925/crystal-reports-how-to-set-database-credentials) –

Trả lời

1

Cuối cùng tìm thấy giải pháp từ here

Điều duy nhất là, tôi cần phải thiết lập các thông tin cơ sở dữ liệu trong thời gian chạy cho Crystal Report để hoạt động tốt.

cryRpt.SetDatabaseLogon("user", "password", "server", "database") 
0

Vấn đề thường gặp này chỉ xảy ra với phiên bản cũ hơn của người gọi CrystalReports từ VB đến .Net world.

Không có gì phải lo lắng. Vui lòng sử dụng như thế này .........

connectionInfo.DatabaseName = "MahendrenDataBase" 

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

connectionInfo.UserID = "UID"; 

connectionInfo.Password="Pwd" 
0

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Dim rpt As New RptCashbill

 ''''''fill Report data'''''' 
    CType(rpt,ReportDocument).ExportToDisk(ExportFormatType.PortableDocFormat,"C:/Report.pdf") 
Các vấn đề liên quan