• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Generate a crystal report from a sql stored procedure.....


I want to write a aspx page where it will display the crystal report. I will be passing some parameters to the sql stored procedure and depending on the result, i have to display the crystal report, how can i do that. Is that possible...

  • 2
1 Solution
Yes, it's possible..

First, get the results of the stored procedure into a typed dataset
Second, Create a Crystal Report based on the Typed DataSet
Last, Add a Crystal Report Viewer to your aspx page, and set the ReportSource to the Crystal Report
This will load the report (OrdersReport.rpt) with a field from a Stored Procedure in which I am passing a "@OrderID" input parameter in:

Private Sub CrystalReportViewer2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer2.Load

      Dim spParam As String = "4965"               <<<< I'm hard coding here for testing
      Dim paramFields As CrystalDecisions.Shared.ParameterFields
      Dim paramField As CrystalDecisions.Shared.ParameterField
      Dim spValue As CrystalDecisions.Shared.ParameterDiscreteValue
      paramFields = New CrystalDecisions.Shared.ParameterFields
      paramField = New CrystalDecisions.Shared.ParameterField
      paramField.ParameterFieldName = "@OrderID"     <<<<<<< from stored procedure
      spValue = New CrystalDecisions.Shared.ParameterDiscreteValue
      spValue.Value = spParam
      CrystalReportViewer2.ParameterFieldInfo = paramFields
      Me.CrystalReportViewer2.ReportSource = New OrdersReport
   End Sub
These are basically the steps I used:

Add New item: Crystal Report . . pick Expert, Blank, or Existing.

Choose Data Source: use
OLD DB (ADO) for SQL Server, Oracle, MS Jet (Access, Exel)
Project Data for ADO.NET datasets from your application
ODBC DB (RDO) for all other ODBC-compliant drivers
Database Files for file-type database formats (.mdb) used in previous versions of CR
More Data Sources for XML files, Access/Excel through DAO, Crystal Field Definitions (TTX)

When adding more than one table, you will need to link them.
Add fields through Fields tab.

Add a CrystalReportViewer to the form.

Drag a ReportDocument from the Components section on the form.
Choose the report to be opened (will be a "typed" report).  

Now put code in Page_Load or here:

Private Sub CrystalReportViewer2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer2.Load

      Me.CrystalReportViewer2.ReportSource = New OrdersReport

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now