Dear All,

I have a problem i have made setup of my project when i install it and run the program it asks for the complete path of database like this "C:\Paymentsystem\PaymentSystem\bin\Debug"

is there any way i want to change the path i mean i want to place database in d drive please help.

6 Years
Discussion Span
Last Post by Naveed_786

Yes. You do that in the connection string.
Assuming that you're using an Access database, then the connection string might look something like this.
Notice the Data Source path.

Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mydatabase.mdb;User Id=admin;Password=;")

Actually i am using this connecting string

Dim cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\Payment.mdb;"

I see.
Well, if you want to load a database from another drive you will have to change that.
In other words, replace Application.StartupPath with a hardcoded path: D:\<path_to_database>\Payment.mdb


Ok now the problem is with report when i run it throws exception load report error i am using this code:

If TextBox1.Text = "" Then
            MessageBox.Show("Please enter PlotNo!", "ALI ENTERPRISES", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        TextBox1.Visible = False
        Button1.Visible = False
        Dim cryRpt As New ReportDocument
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = TextBox1.Text
        'crParameterDiscreteValue.Value = TextBox2.Text
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields()
        crParameterFieldDefinition = _
        crParameterValues = crParameterFieldDefinition.CurrentValues


        CrystalReportViewer1.ReportSource = cryRpt
    End Sub

What should i do to resolve this problem please help me.


Assuming that the error occurs on line 8, then the most likely cause is the path.
Is it correct?


yes error comes on line no 8 ok can i use this code here "Application.StartupPath"


Application.StartupPath points to the folder where your appliction is executed from.

For example, if you install your application to "C:\SomeKindOfApp\myapp.exe", then Application.StartupPath will point to "C:\SomeKindOfApp".

So, if the report you wish to load is on another disk, then Application.StartupPath won't work.
However, if the report file is located in the same folder as your executable, then Yes, Application.StartupPath will work perfectly.


What are the properties for the report file?

Check "Build Action", if it's set to Embedded Resource, then change that to None.
Check "Copy to Output Directory", if it's set to Do not copy, then change that to Copy always.

You need to make sure that the report file resides in the directory you are trying to load it from.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.