Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Provide value to SQL SP parameter from VB.NET via CrystalReportDocument

(I'm having a tough time using this editor -- why can't I paste into it?)

I'm developing a CrystalReportDocument from within Visual Studio for the first time, and cannot get the report to work.  My environment is VB.NET in Visual Studio 2013, Crystal Reports for Visual Studio 2013 SP9, and SQL Server Express 2014.

The report Invoice.rpt appears in the Solution Explorer window of my VB.NET project. It uses a SQL Server SP containing one parameter, @RepairOrderNumber, that needs to be supplied at run time. Here's my code that attempts to invoke the report:

     Private Sub frmReportViewer_Load(sender As Object, e As EventArgs) Handles MyBase.Load

          Try

               Dim rptInvoice As New SD.Invoice          ' this is supposed to reference Invoice.rpt

               Dim crParameterField As New ParameterField

               Dim crParameterFields As New ParameterFields

               Dim crParameterDiscreteValue As New ParameterDiscreteValue


               crParameterField.Name = "@RepairOrderNumber"

               crParameterDiscreteValue.Value = 2        ' hard-coded for now to print invoice number 2 

               crParameterField.CurrentValues.Add(crParameterDiscreteValue)

               crParameterFields.Add(crParameterField)


               crViewer.ParameterField.Info = crParameterFields

               crViewer.ReportSource = rptInvoice


          Catch ex As Exception

               ' error logging code omitted, but no errors were logged.


          End Try

     End Sub


When I run the above code, the Invoice report is displayed in the viewer, however it's empty -- apparently no result set is being returned.  When I preview the report in the designer and supply a parameter value when prompted, the report displays perfectly.

What's wrong with the above code?

Thanks in advance...

Former Member
replied

You've got some pretty weird behaviors going on there;

Report appears, then disappears(?).

Report prompts for parameter even though you provide the param in code?

Two load report fails?

I really would go to square one as I described in my initial post;

One liner app load report via the viewer - get that to work.

Next add code to load report via the engine - get that to work.

Add parameter code to the load report via engine.

All in a new app. The behavior of the old app does not make sense. If this is a web app, you will have to put the report into a session:

KBA: 1985571 - How to use sessions in web applications using the Crystal Reports viewer (the complete code)

- Ludek

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question