Click here to Skip to main content
15,905,068 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my first time using Crystal reports. What i am trying to do is when i highlight a row in datagridview and click report button, only the highlighted row will be displayed in the Crystal report viewer just like shown in the image.

Expected Result
Image of Expected Result

Report Button code

VB
Private Sub btnReport_Click(sender As Object, e As EventArgs) Handles btnReport.Click
       Dim report As New ReportDocument
       report.SetParameterValue("StudentRecord", dgv1.SelectedRows(0).Cells(0).Value)
       report.Load("C:\Users\harold\Documents\Visual Studio 2012\Projects\SASApp\SASApp\MyReport.rpt")
       CrystalReportViewer1.ReportSource = report
       CrystalReportViewer1.Refresh()
   End Sub


Whenever i click the report button, i get an error of

LoadSaveReportException was unhandled / Invalid report file path with this line
VB
report.SetParameterValue("StudentRecord", dgv1.SelectedRows(0).Cells(0).Value)


I get the "StudentRecord" in the parameter fields that I made in Crystal report as the image below shown

Image
Image of Parameter fields

Can anyone help me to figure out whats wrong with my code. Thanks

What I have tried:

I have tried some solutions here but no luck.
Posted
Updated 16-Mar-16 4:19am
v2

1 solution

You need to load the report before attempting to pass in the parameter value

Try
VB
...
report.Load("C:\Users\harold\Documents\Visual Studio 2012\Projects\SASApp\SASApp\MyReport.rpt")
report.SetParameterValue("StudentRecord", dgv1.SelectedRows(0).Cells(0).Value)
...
 
Share this answer
 
Comments
Diether Silverious 17-Mar-16 2:19am    
thanks CHill60
CHill60 17-Mar-16 5:12am    
My pleasure

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900