
Crystal Reports export to PDF in VB.NET
Having a problem exporting via
Crystal Reports to a PDF File.
I'm using CR v8.0, and the Crystal Reports.net that comes with visual
studio.net (It's not 8.0; higher - probably v9.0).
We've developed a standard "pull" rpt using CR v8.0 (outside of .NET)
and the code (shown below) will export, no problem. However, we wish
to be able to override the datasource the rpt will use ("push") by
passing in a new dataset via the .setdatasource method of the untyped
report document.
No error results, but the ORIGINAL datasource associated with the
design report is what is used. the .setdatasource command is
ignored/not used.
here's the code: anyone have any ideas? I've spent hours searching the
web/boards for similar issues, but haven't found any yet:
Dim RptEngine As ReportDocument = New ReportDocument()
Dim ds As DataSet = New DataSet()
Dim oleConn As New System.Data.SqlClient.SqlConnection("Data
Source=SOMESQLSERVER;Initial Catalog=AuditProbe;uid=sa;pwd=;")
Dim oleAdapter As New System.Data.SqlClient.SqlDataAdapter()
Dim ro As ReportObjects
Dim grp As GroupNameFieldDefinitions
'select data from new source
oleAdapter.SelectCommand = New
System.Data.SqlClient.SqlCommand("Select * From CO4_Report18Print",
oleConn)
'fill data using tablename the rpt file was designed with
oleAdapter.Fill(ds, "CO4_Report17Print")
RptEngine.Load("Y:\Development\TestApp\RRS_TEST01.rpt")
RptEngine.SetDataSource(ds)
Dim diskOpts As New [Shared].DiskFileDestinationOptions()
RptEngine.ExportOptions.ExportFormatType =
[Shared].ExportFormatType.PortableDocFormat
RptEngine.ExportOptions.ExportDestinationType =
[Shared].ExportDestinationType.DiskFile
diskOpts.DiskFileName = "C:\rpt1.pdf"
RptEngine.ExportOptions.DestinationOptions = diskOpts
RptEngine.Export()
RptEngine.Close()
RptEngine = Nothing
Any help would be appreciated.