Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi, Im new to the vb.net and crystal report. i wrote a code to generate cryatal report based on the combo box filtering values.
Ex:- I have two combo box named combo 1 and 2 to filter year with committee no. then it should display relevant report consists with other required fileds from db. when i run this code it says "Invalid report file path". can anyone help me to find the issue in my code please.



Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Database1.accdb")
If ComboBox1.Text = "2023" And ComboBox2.Text = "1" Then

            Try
                Dim sql As String
                Dim cmd As New OleDb.OleDbCommand
                Dim dt As New DataTable
                Dim da As New OleDb.OleDbDataAdapter
                Dim cryRpt8 As New ReportDocument

                con.Open()

                
                sql = "select r.Department, r.officerName, b.Requisition_date, b.book_ID, b.title, b.Authors, b.edition, b.Quantity, b.pdf_availability, b.Book_type, q.bidder1, q.bidder2, q.bidder3, q.up1currancy, q.up2currancy, q.up3currancy, q.unitprice_b1, q.unitprice_b2, q.unitprice_b3, q.ac1currancy, q.ac2currancy, q.ac3currancy, q.ac1, q.ac2, q.ac3, q.fa1currancy, q.fa2currancy, q.fa3currancy, q.fa1, q.fa2, q.fa3, q.committee_No FROM ((reqesition r INNER JOIN books b ON b.reqesitionID=r.reqesitionID) INNER JOIN quotation q ON q.BookID=b.book_ID) where q.committee_No LIKE '%" & 1 & "%' and b.Requisition_date LIKE '%" & 2023 & "%' "
                cmd.Connection = con
                cmd.CommandText = sql
                poppp = cmd.ExecuteNonQuery

                da.SelectCommand = cmd
                da.Fill(dt)

                cryRpt8.SetDataSource(cmd)
                cryRpt8.Load("E:\Final Book purchasing System\Final Book purchasing System\CrystalReport63.rpt")
                CrystalReportViewer1.ReportSource = cryRpt8
                CrystalReportViewer1.Refresh()

            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                con.Close()
            End Try


What I have tried:

Hi, Im new to the vb.net and crystal report. i wrote a code to generate cryatal report based on the combo box filtering values.
Ex:- I have two combo box named combo 1 and 2 to filter year with committee no. then it should display relevant report consists with other required fileds from db. when i run this code it says "Invalid report file path". can anyone help me to find the issue in my code please.
Posted
Updated 13-Aug-23 22:13pm
Comments
Richard Deeming 14-Aug-23 4:02am    
Hard-coding the database and report file paths is a terrible idea. It means you will never be able to distribute your application to other users - my computer doesn't even have an E: drive, let alone the two files your code is relying on. And even if it did, they're unlikely to be the same files that you have on your machine.

"Invalid report file path"
The message suggests that it cannot create the report on the filename you have selected. So check the drive and path are valid.
 
Share this answer
 
Comments
Andre Oosthuizen 14-Aug-23 4:00am    
This is where you need to check the path, it is incorrect - 'cryRpt8.Load("E:\Final Book purchasing System\Final Book purchasing System\CrystalReport63.rpt")'
There are two paths involved here:
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Database1.accdb")
And
cryRpt8.Load("E:\Final Book purchasing System\Final Book purchasing System\CrystalReport63.rpt")
Most likely it's the second of these, but you should use the debugger to find out which, and then check the drive / path combo to make sure it all exists.

In addition, it's a poor idea to keep your DB in the root folder of any drive as it's likely that write access to the root will be further restricted in future OS releases for security reasons (it already requires admin permission for your boot drive, normally C:)
Generally speaking, you should keep data (including databases and reports) under the User account: Where Should I Store My Data?[^] suggests some better places.

And you should never hard code paths: always use a configuration file, so that the path can be changed (or set by your installation utility) without the need to recompile the whole app. Because I have many apps which use databases, I use this: Instance Storage - A Simple Way to Share Configuration Data among Applications[^] but it may be a little overkill for your needs.
 
Share this answer
 

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