Solved

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

Posted on 2014-09-09
8
213 Views
Last Modified: 2014-09-10
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
            Dim crParameterField As New ParameterField
            Dim crParameterFields As New ParameterFields
            Dim crParameterDiscreteValue As New ParameterDiscreteValue

            crParameterField.Name = "@RepairOrderNumber"
            crParameterDiscreteValue.Value = miRepairOrderNumber
            crParameterField.CurrentValues.Add(crParameterDiscreteValue)
            crParameterFields.Add(crParameterField)

            crViewer.ParameterFieldInfo = crParameterFields
            crViewer.ReportSource = rptInvoice

        Catch ex As Exception
            ' error handling code omitted, but no error is raised.

        End Try
    End Sub

Open in new window

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?
0
Comment
Question by:petekipe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 40314746
When you view the report if you click REFRESH what happens?

mlmcc
0
 

Author Comment

by:petekipe
ID: 40314752
By the way, miRepairOrderNumber is defined as an Integer, as is @RepairOrderNumber in the SP.
0
 

Author Comment

by:petekipe
ID: 40314769
I Forgot to mention that before the empty report appears, I'm getting the good old "Load report failed." message twice, then the empty report appears.  If I click Refresh, I'm prompted for a parameter value.  When I supply a valid value, the report is displayed correctly.
0
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 
LVL 101

Accepted Solution

by:
mlmcc earned 500 total points
ID: 40314804
I haven't built a viewing application in .Net that allows for parameters.  Your code looks correct.

Do the error logs show anything useful for the load errors you see?

mlmcc
0
 

Author Comment

by:petekipe
ID: 40314817
Does Crystal produce an error log?  If so, where?  I'm logging errors that are raised in VB, but in this case, no error is being raised.  BTW, thanks for sticking with me on this -- much appreciated.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 40315038
No Crystal doesn't create its own.  It would be either in the database error log or the system error log.

mlmcc
0
 

Author Comment

by:petekipe
ID: 40315666
Problem solved.  To try to debug the problem, I created a brand new project with one form, put a viewer control on it, and included the code from my original post in the form -- and the report worked perfectly.  So I went back to my original project, removed the viewer control from my report viewer form, put a new control on the form, and the problem went away!  Go figure...

Thanks for your help, mlmcc.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 40315711
I doubt I would have suggested that idea.

mlmcc
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question