DataDirectory for Connection String

It's easy to change the location/name of a dataset using the project properties - but how can you change it during run time

The property shows Data Source=|DataDirectory|\filename, but there is no apparent way to access 'DataDirectory' in the code.

Any ideas




Answer this question

DataDirectory for Connection String

  • Chernomor

    You can access the value with ApplicationDeployment.DataDirectory. It is a readonly property that points to the applications data directory on the local disk.


  • ydt

    hi,

    the table adapter has connection property you can use it


    Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '//edit the connection string fron user entery then reconnect again

    Dim conStr = "C:\Documents and Settings\Haitham\Desktop\dateTesting.mdb"

    Me.DateTTableAdapter.Connection.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & conStr
    DateTestingDataSet.Clear()
    Me.DateTTableAdapter.Fill(Me.DateTestingDataSet.dateT)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    '//this is the original settings

    Me.DateTTableAdapter.Fill(Me.DateTestingDataSet.dateT)
    End Sub
    End
    Class


    hope this helps



  • Michael Thorn

    Worked like a charm! Exactly what I was looking for.

    Thanks.



  • !=MaYHeM

    applicationdeployment doesn't really help me as I want the user to set the data directory and/or file name. A fileopendialog allows the user to select the location, but I'm unable to find a way to get the program to use that value in the database conector - it always want's to use the value that the creator puts in the project settings.

  • DataDirectory for Connection String