Exporting Crystal Report to PDF through ASP.Net

arya

New member
Joined
Jan 23, 2006
Messages
3
Programming Experience
3-5
Hi guys,

I am dynamically generating the report document using XML dataset.
It works fine until I try to export it to PDF format. There is a problem
of login failure... Please Help

This is my code:

VB.NET:
'customising
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim qstr, stat As String
Dim sd, ed As String
 
qstr = "Select * from BMReport_View where name like '" _
TextBox1.Text + "%' "
 
load_report(qstr)
end sub
 
'********************
'report generating function
Sub load_report(ByVal qry As String)
Dim ad As New SqlDataAdapter
Dim ds As New BM_Rpt_Data
Dim dt As New DataTable
Dim oTable As Table
Dim oLogOnInfo As New TableLogOnInfo
 
Try
con.Open()
ad = New SqlDataAdapter(qry, con) '"BM_Report '" & iEmpName & "','" & iStatus & "'," & IQrySDate & "," & IQryEDate & "", con)
ds = New BM_Rpt_Data
ad.Fill(ds, "BMReport_View")
ad.Fill(dt)
con.Close()
 
For Each oTable In rpt.Database.Tables
oLogOnInfo = oTable.LogOnInfo
With oLogOnInfo
.ConnectionInfo.ServerName = "SERVER"
.ConnectionInfo.DatabaseName = "CraySys"
.ConnectionInfo.UserID = "UserCS"
.ConnectionInfo.Password = ""
End With
oTable.ApplyLogOnInfo(oLogOnInfo)
Next
 
rpt.SetDataSource(dt)
 
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.BorderStyle = BorderStyle.Inset
CrystalReportViewer1.DisplayGroupTree = False
CrystalReportViewer1.Visible = True
Catch ex As Exception
Label10.Text = "An error has occurred"
Label10.Visible = True
CrystalReportViewer1.Visible = False
End Try
End Sub
 
'*********************
'exporting report
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim oStream As MemoryStream 'using System.IO
Try
oStream = rpt.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.BinaryWrite(oStream.ToArray())
Response.End()
Catch ex As Exception
Label10.Text = "Unable to export"
Label10.Visible = True
End Try
End Sub
 
Last edited by a moderator:

Latest posts

Back
Top