We've had the most success setting the datasource at runtime and then
outputting the report to a pdf. You can design the report based on a
data schema, xml document or sample data set and then at runtime set the
datasource which contains your new data. We had a great deal of
difficulty using the crystal report objects in general and this way
seems to provide a more or less universal way to access the reports
without having to go too deep into crystal's object model. Using the pdf
file format seems to eliminate problems with viewers.
Dim oCN As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim oCMD As New SqlCommand("EmployeeTime", oCN)
oCMD.CommandType =3D CommandType.StoredProcedure
Dim prmEmpID As New SqlParameter("@EmpID", SqlDbType.Char, 8)
prmEmpID.Value =3D cmbEmployees.SelectedItem.Value
oCMD.Parameters.Add(prmEmpID)
Dim prmFirstDate As New SqlParameter("@StartDate",
SqlDbType.SmallDateTime)
prmFirstDate.Value =3D firstDate
oCMD.Parameters.Add(prmFirstDate)
Dim prmLastDate As New SqlParameter("@EndDate",
SqlDbType.SmallDateTime)
prmLastDate.Value =3D lastDate
oCMD.Parameters.Add(prmLastDate)
Dim err As Exception
Dim ds As New DataSet()
Try
oCN.Open()
Dim oAdpt As New SqlDataAdapter(oCMD)
oAdpt.Fill(ds, "EmployeeTime")
Catch err
Response.Write(err.Message)
Finally
oCN.Close()
End Try
Dim crReport As New ReportDocument()
Dim crExportOptions As ExportOptions
Dim crDiskFileOptions As DiskFileDestinationOptions
Dim fName As String
crReport.Load(Server.MapPath("rptTime.rpt"))
crReport.SetDataSource(ds)
crReport.DataDefinition.FormulaFields("subTitle").Text =3D
Chr(34) & RTrim(cmbEmployees.SelectedItem.Text) & " time for " &
CStr(firstDate) & " to " & CStr(lastDate) & Chr(34)
fName =3D Server.MapPath(Session.SessionID.ToString & ".pdf")
crDiskFileOptions =3D New DiskFileDestinationOptions()
crDiskFileOptions.DiskFileName =3D fName
crExportOptions =3D crReport.ExportOptions
With crExportOptions
.DestinationOptions =3D crDiskFileOptions
.ExportDestinationType =3D ExportDestinationType.DiskFile
.ExportFormatType =3D ExportFormatType.PortableDocFormat
End With
Try
crReport.Export()
Catch err
Response.Write(err.Message)
Finally
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType =3D "application/pdf"
Response.WriteFile(fName)
Response.Flush()
Response.Close()
System.IO.File.Delete(fName)
End Try
Regards,
David Reckner
-----Original Message-----
From: mams_developer@h... [mailto:mams_developer@h...]
Sent: Wednesday, November 20, 2002 3:26 AM
To: ASPX_Professional
Subject: [aspx_professional] Crystal Reports Problem
Hi all
Can anyone please help me and my team out of a messy problem? We need
reports in our web based asp.net application. WE tried to make reports
by
passing parameters. But lots of errors cropped up. Please tell how to do
taht.
Then we tried to create reports thru web services.When we add the
references of this service in our project, we are only able to access
the
the last publish report as web service. We are giving below the part of
the code of reference.vb related to report service
Please throw light on both ways of creating reports.
Also, what is ActiveReports.net?????
Thanks a lot
Arti Mahendra Sharma
'------------------------------------------------------------------------
--
----
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.0.3705.0
'
' Changes to this file may cause incorrect behavior and will be lost
if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------
--
----
Option Strict Off
Option Explicit On
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
'This source code was auto-generated by Microsoft.VSDesigner, Version
1.0.3705.0.
'
Namespace dotnetsrv
'<remarks/>
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Web.Services.WebServiceBindingAttribute
(Name:=3D"rptAmmendedPOServiceSoap",
[Namespace]:=3D"http://crystaldecisions.com/reportwebservice/9.1/"), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(ParameterValue))
> _
Public Class rptAmmendedPOServiceSoap
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
'<remarks/>
Public Sub New()
MyBase.New
Me.Url
=3D "http://dotnetsrv/ERPDevWebService/rptAmmendedPOService.asmx"
End Sub
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/GetGroupLevelData",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function GetGroupLevelData
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
request As GroupLevelDataRequest) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("GetGroupLevelData",
New
Object() {request})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginGetGroupLevelData(ByVal request As
GroupLevelDataRequest, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("GetGroupLevelData", New Object()
{request}, callback, asyncState)
End Function
'<remarks/>
Public Function EndGetGroupLevelData(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/GetReportInfo",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function GetReportInfo
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As RequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("GetReportInfo", New
Object
() {reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginGetReportInfo(ByVal reqContext As
RequestContext, ByVal callback As System.AsyncCallback, ByVal asyncState
As Object) As System.IAsyncResult
Return Me.BeginInvoke("GetReportInfo", New Object()
{reqContext}, callback, asyncState)
End Function
'<remarks/>
Public Function EndGetReportInfo(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/Export",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function Export
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As ExportRequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("Export", New Object()
{reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginExport(ByVal reqContext As
ExportRequestContext, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("Export", New Object() {reqContext},
callback, asyncState)
End Function
'<remarks/>
Public Function EndExport(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/Refresh",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function Refresh
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As RequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("Refresh", New
Object()
{reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginRefresh(ByVal reqContext As RequestContext,
ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As
System.IAsyncResult
Return Me.BeginInvoke("Refresh", New Object() {reqContext},
callback, asyncState)
End Function
'<remarks/>
Public Function EndRefresh(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/DrillGraph",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function DrillGraph
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As DrillDownRequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("DrillGraph", New
Object()
{reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginDrillGraph(ByVal reqContext As
DrillDownRequestContext, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("DrillGraph", New Object()
{reqContext},
callback, asyncState)
End Function
'<remarks/>
Public Function EndDrillGraph(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/FindGroup",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function FindGroup
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As FindGroupContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("FindGroup", New
Object()
{reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginFindGroup(ByVal reqContext As
FindGroupContext, ByVal callback As System.AsyncCallback, ByVal
asyncState
As Object) As System.IAsyncResult
Return Me.BeginInvoke("FindGroup", New Object()
{reqContext},
callback, asyncState)
End Function
'<remarks/>
Public Function EndFindGroup(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/FindText",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function FindText
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As FindTextRequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("FindText", New
Object()
{reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginFindText(ByVal reqContext As
FindTextRequestContext, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("FindText", New Object() {reqContext},
callback, asyncState)
End Function
'<remarks/>
Public Function EndFindText(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/GetLastPageNumber",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function GetLastPageNumber
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As ReportPageRequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("GetLastPageNumber",
New
Object() {reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginGetLastPageNumber(ByVal reqContext As
ReportPageRequestContext, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("GetLastPageNumber", New Object()
{reqContext}, callback, asyncState)
End Function
'<remarks/>
Public Function EndGetLastPageNumber(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/GetTotaller",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function GetTotaller
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As TotallerRequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("GetTotaller", New
Object
() {reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginGetTotaller(ByVal reqContext As
TotallerRequestContext, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("GetTotaller", New Object()
{reqContext}, callback, asyncState)
End Function
'<remarks/>
Public Function EndGetTotaller(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/GetPage",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function GetPage
(<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ByVal
reqContext As PageRequestContext) As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("GetPage", New
Object()
{reqContext})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginGetPage(ByVal reqContext As
PageRequestContext, ByVal callback As System.AsyncCallback, ByVal
asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("GetPage", New Object() {reqContext},
callback, asyncState)
End Function
'<remarks/>
Public Function EndGetPage(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
<System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://crystaldecisions.com/reportwebservice/9.1/TestReport",
RequestNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
ResponseNamespace:=3D"http://crystaldecisions.com/reportwebservice/9.1/",
Use:=3DSystem.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=3DSystem.Web.Services.Protocols.SoapParameterStyle.Wrappe
d)
> _
Public Function TestReport() As
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=3Dtrue)>
ResponseContext
Dim results() As Object =3D Me.Invoke("TestReport", New
Object(-
1) {})
Return CType(results(0),ResponseContext)
End Function
'<remarks/>
Public Function BeginTestReport(ByVal callback As
System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("TestReport", New Object(-1) {},
callback, asyncState)
End Function
'<remarks/>
Public Function EndTestReport(ByVal asyncResult As
System.IAsyncResult) As ResponseContext
Dim results() As Object =3D Me.EndInvoke(asyncResult)
Return CType(results(0),ResponseContext)
End Function
End Class
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.419 / Virus Database: 235 - Release Date: 11/13/2002
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.419 / Virus Database: 235 - Release Date: 11/13/2002