Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I get this error while exporting my report to Word: "Missing parameter values" My code looks like this

VB
Dim db1 As New DBLevel
                Dim conn = db1.GetCon()
                Dim cmd As New SqlCommand
                Dim da As New SqlDataAdapter
                Dim dss As New DataSet


                cmd.CommandText = "[procReport"
                cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.NVarChar)).Value = Request.QueryString("ID")
        
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Connection = conn
                da.SelectCommand = cmd
                da.Fill(dss)


                oRPT.Load(Server.MapPath("rptReports/ReportWord.rpt"))
                oRPT.SetDataSource(dss.Tables(0))

                oRPT.SetParameterValue("@ID", Request.QueryString("ID"))

                Me.CrystalReportViewer1.ReportSource = oRPT
                Me.CrystalReportViewer1.DataBind()

                Dim margins = New PageMargins
                oRPT.PrintOptions.PaperSize = PaperSize.PaperA4
                margins = oRPT.PrintOptions.PageMargins
                margins.leftMargin = 750
                margins.topMargin = 350
                margins.bottomMargin = 40
                margins.rightMargin = 550


                Try
                    Dim CrExportOptions As CrystalDecisions.Shared.ExportOptions
                  
                    Dim CrDiskFileDestinationOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions()
                    Dim CrFormatTypeOptions As New CrystalDecisions.Shared.PdfRtfWordFormatOptions()



                    CrDiskFileDestinationOptions.DiskFileName = Server.MapPath("~/Report.doc")
                    Dim targetFile As System.IO.FileInfo = New System.IO.FileInfo(Server.MapPath("~/Report.doc"))


                    CrExportOptions = oRPT.ExportOptions

                    With CrExportOptions
                        .ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
                        .ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows
                        .DestinationOptions = CrDiskFileDestinationOptions
                        .FormatOptions = CrFormatTypeOptions
                    End With

                    oRPT.Export()
                    Response.Clear()
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + targetFile.Name)
                    Response.AddHeader("Content-Length", targetFile.Length.ToString)
                    Response.ContentType = "application/octet-stream"
                    Response.WriteFile(targetFile.FullName)


                Catch ex As Exception
                    Response.Write(ex.ToString)
                End Try
                oRPT.Clone()
                oRPT.Dispose()
Posted
Updated 18-Jun-15 21:50pm
v3
Comments
Sergey Alexandrovich Kryukov 19-Jun-15 3:07am    
In what line?
The solution: don't miss parameter values. Locate your line and check with the documentation on every method you call. Fix your usage according to the documentation.
—SA
xszaboj 19-Jun-15 7:59am    
Try to give us more detail about error. ;)
What line, what method etc..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900