Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rptSummary As ReportDocument
Dim strExportFile As String
Dim objExOpt As ExportOptions
Dim objDiskOpt As New DiskFileDestinationOptions
strExportFile = "blankreview.pdf"
' Declare Report
Dim rptBlank As New crBlankSR
' Selection string for Data Adapter
Dim strSQL As String = "SELECT * from tblQuestions where QuestionYear = '" & Session("FY") & "' ORDER BY QuestionNbrID"
' Open Connection
SqlCon.Open()
' Delcare Adapter
Dim da As SqlDataAdapter
' Instantiate Adapter
da = New SqlDataAdapter(strSQL, SqlCon)
' Declare Data Set
Dim ds As datasetBlankSR ' *** 1st Run I have DataSet Here
' Instantiate Data Set
ds = New datasetBlankSR ' *** 1st Run I have DataSet Here
' Fill Data Set
da.Fill(ds, "tblQuestions")
ds.WriteXMLSchema("datasetBlankSR.xsd") ' *** Remove this after 1st Run
' Set Report Data Source
rptBlank.SetDataSource(ds)
rptSummary = rptBlank
objDiskOpt.DiskFileName = Server.MapPath(".") & "\" & strExportFile
objExOpt = rptSummary.ExportOptions
objExOpt.ExportDestinationType = ExportDestinationType.DiskFile
objExOpt.ExportFormatType = ExportFormatType.PortableDocFormat
objExOpt.DestinationOptions = objDiskOpt
rptSummary.Export()
rptSummary.Close()
' Close Connection
SqlCon.Close()
' Make sure all connections, readers and commands are closed
ds.Dispose()
da.Dispose()
If SqlCon.State <> ConnectionState.Closed Then SqlCon.Close()
' Send user to PDF report
Response.Redirect(strExportFile)
End Sub
After this runs once I remove or change the noted lines and create a Crystal Report called crBlankSR.rpt and use the
dataset that [ds.WriteXMLSchema("datasetBlankSR.xsd")] created as my datasource. After designing and tweaking the report I run the app again and the report is exported to PDF and all is well in the world. Hope this helps anyone out there with the same issues.
Thanks for all the help guys. Ron. BTW: I have a disclaimer on my report that states "No one is allowed to ask for changes EVER!!!" hehe
Capt_Ron
Member
586 Points
139 Posts
Re: Trying to Convert to PDF - Help
Oct 28, 2004 11:33 PM|LINK
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim rptSummary As ReportDocument Dim strExportFile As String Dim objExOpt As ExportOptions Dim objDiskOpt As New DiskFileDestinationOptions strExportFile = "blankreview.pdf" ' Declare Report Dim rptBlank As New crBlankSR ' Selection string for Data Adapter Dim strSQL As String = "SELECT * from tblQuestions where QuestionYear = '" & Session("FY") & "' ORDER BY QuestionNbrID" ' Open Connection SqlCon.Open() ' Delcare Adapter Dim da As SqlDataAdapter ' Instantiate Adapter da = New SqlDataAdapter(strSQL, SqlCon) ' Declare Data Set Dim ds As datasetBlankSR ' *** 1st Run I have DataSet Here ' Instantiate Data Set ds = New datasetBlankSR ' *** 1st Run I have DataSet Here ' Fill Data Set da.Fill(ds, "tblQuestions") ds.WriteXMLSchema("datasetBlankSR.xsd") ' *** Remove this after 1st Run ' Set Report Data Source rptBlank.SetDataSource(ds) rptSummary = rptBlank objDiskOpt.DiskFileName = Server.MapPath(".") & "\" & strExportFile objExOpt = rptSummary.ExportOptions objExOpt.ExportDestinationType = ExportDestinationType.DiskFile objExOpt.ExportFormatType = ExportFormatType.PortableDocFormat objExOpt.DestinationOptions = objDiskOpt rptSummary.Export() rptSummary.Close() ' Close Connection SqlCon.Close() ' Make sure all connections, readers and commands are closed ds.Dispose() da.Dispose() If SqlCon.State <> ConnectionState.Closed Then SqlCon.Close() ' Send user to PDF report Response.Redirect(strExportFile) End SubAfter this runs once I remove or change the noted lines and create a Crystal Report called crBlankSR.rpt and use the dataset that [ds.WriteXMLSchema("datasetBlankSR.xsd")] created as my datasource. After designing and tweaking the report I run the app again and the report is exported to PDF and all is well in the world. Hope this helps anyone out there with the same issues. Thanks for all the help guys. Ron. BTW: I have a disclaimer on my report that states "No one is allowed to ask for changes EVER!!!" hehe