Link to home
Start Free TrialLog in
Avatar of LeighWardle
LeighWardleFlag for Australia

asked on

How to programmatically change the path of a Dataset?

Hi Experts,

I have a simple database example that works with a Dataset that was set up with a wizard.
I now want to programmatically change the path of the Dataset.

Right now I can only see the path of the Dataset ("NorthwindDataSet") in the app.config file:

app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="WindowsApplication9.My.MySettings.NorthwindConnectionString"
            connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb"
            providerName="System.Data.OleDb" />
    </connectionStrings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
    </startup>
</configuration>

Open in new window


Here's my startup form:

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'NorthwindDataSet.Customers' table. You can move, or remove it, as needed.
        Me.CustomersTableAdapter.Fill(Me.NorthwindDataSet.Customers)

        'Highlight row when cell is clicked in DataGridView contol
        With Me.DataGridView1
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
        End With
    End Sub
End Class

Open in new window


Regards,
Leigh
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you mean path of the database? Change the connection string (line 7 in app.config) to point to new path.
Avatar of LeighWardle

ASKER

Yes, change the path of the .mdb file while the program runs.
>Yes, change the path of the .mdb file while the program runs.

While the program runs? You would need to construct the connection string in code then. I would also suggest to avoid using wizards.
I know how to define the connection  string in code, but how how do I use it?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, CodeCruiser.

Regards,
Leigh