R
Radx
Hello All
I am having a very hard timt exporting crystal report to PDF document
in my ASPX page. I am able to generate the PDF document , but the i
am not able to pass the parameter to the report (Crystal). It looks
like , it completely ignores the parameter i am passing and just
brings all the records from the database.
When i run the report directly from Crystal , it works fine. So I
know report works fine . For some strange reason , the parameter i
am passing are not applied to the report.
Can anyone share your ideas of how to do this !!!.. Thank you
Here is the code
Dim SActivityID As Long = 0
Dim iAppUserId As Long = 0
Dim myReport As ReportDocument = New ReportDocument
Dim s As Stream
Dim crConnectionInfo As CrystalDecisions.Shared.ConnectionInfo
Dim pDv As ParameterDiscreteValue = New ParameterDiscreteValue
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTableLogOnInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim crDatabase As
CrystalDecisions.CrystalReports.Engine.Database
Dim parameterFieldDef As ParameterFieldDefinition
Dim parameterValues As ParameterValues
Dim ExpOptions As ExportOptions
Dim req As ExportRequestContext
iAppUserId = CLng(Session("SSXYUser_ID"))
If Not IsPostBack Then
If iAppUserId <= 0 Then
Response.Redirect("Login.aspx")
Response.ClearHeaders()
Else
crConnectionInfo = New
CrystalDecisions.Shared.ConnectionInfo
crConnectionInfo.ServerName = "XXXXXX"
crConnectionInfo.DatabaseName = "YYYYYYYYYYY"
crConnectionInfo.UserID = "NO"
crConnectionInfo.Password = "VVVVVVVV"
myReport.Load("c:\\inetpub\\wwwroot\\XZY\\SpecimenReport.rpt")
crDatabase = myReport.Database
crTables = crDatabase.Tables
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
SActivityID = CLng(Request.Params("SpecimenActID"))
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
pDv.Value = SActivityID
parameterFieldDef =
myReport.DataDefinition.ParameterFields("SpecimenActId")
parameterValues = parameterFieldDef.CurrentValues
parameterValues.Add(pDv)
parameterFieldDef.ApplyCurrentValues(parameterValues)
req = New ExportRequestContext
ExpOptions = New ExportOptions
ExpOptions.ExportFormatType =
ExportFormatType.PortableDocFormat
ExpOptions.FormatOptions = New PdfRtfWordFormatOptions
req.ExportInfo = ExpOptions
s = myReport.FormatEngine.ExportToStream(req)
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
Dim buffer(s.Length) As Byte
s.Read(buffer, 0, Int(s.Length))
Response.BinaryWrite(buffer)
Response.End()
End If
I am having a very hard timt exporting crystal report to PDF document
in my ASPX page. I am able to generate the PDF document , but the i
am not able to pass the parameter to the report (Crystal). It looks
like , it completely ignores the parameter i am passing and just
brings all the records from the database.
When i run the report directly from Crystal , it works fine. So I
know report works fine . For some strange reason , the parameter i
am passing are not applied to the report.
Can anyone share your ideas of how to do this !!!.. Thank you
Here is the code
Dim SActivityID As Long = 0
Dim iAppUserId As Long = 0
Dim myReport As ReportDocument = New ReportDocument
Dim s As Stream
Dim crConnectionInfo As CrystalDecisions.Shared.ConnectionInfo
Dim pDv As ParameterDiscreteValue = New ParameterDiscreteValue
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTableLogOnInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim crDatabase As
CrystalDecisions.CrystalReports.Engine.Database
Dim parameterFieldDef As ParameterFieldDefinition
Dim parameterValues As ParameterValues
Dim ExpOptions As ExportOptions
Dim req As ExportRequestContext
iAppUserId = CLng(Session("SSXYUser_ID"))
If Not IsPostBack Then
If iAppUserId <= 0 Then
Response.Redirect("Login.aspx")
Response.ClearHeaders()
Else
crConnectionInfo = New
CrystalDecisions.Shared.ConnectionInfo
crConnectionInfo.ServerName = "XXXXXX"
crConnectionInfo.DatabaseName = "YYYYYYYYYYY"
crConnectionInfo.UserID = "NO"
crConnectionInfo.Password = "VVVVVVVV"
myReport.Load("c:\\inetpub\\wwwroot\\XZY\\SpecimenReport.rpt")
crDatabase = myReport.Database
crTables = crDatabase.Tables
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
SActivityID = CLng(Request.Params("SpecimenActID"))
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
pDv.Value = SActivityID
parameterFieldDef =
myReport.DataDefinition.ParameterFields("SpecimenActId")
parameterValues = parameterFieldDef.CurrentValues
parameterValues.Add(pDv)
parameterFieldDef.ApplyCurrentValues(parameterValues)
req = New ExportRequestContext
ExpOptions = New ExportOptions
ExpOptions.ExportFormatType =
ExportFormatType.PortableDocFormat
ExpOptions.FormatOptions = New PdfRtfWordFormatOptions
req.ExportInfo = ExpOptions
s = myReport.FormatEngine.ExportToStream(req)
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
Dim buffer(s.Length) As Byte
s.Read(buffer, 0, Int(s.Length))
Response.BinaryWrite(buffer)
Response.End()
End If