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 đỡ.
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. –
@ 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? –
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) –