Reputation:
First, let's have a look at my code:
Private Sub FormLoad(sender As Object, e As EventArgs) Handles MyBase.Load
txtMDF.Text = My.Settings.MDF
End Sub
Assume My.Settings.MDF
has a string value of Application.StartupPath + "\MyDB.mdf"
. I get this result:
But I want the result to be:
I have tried the following links and methods:
Upvotes: 0
Views: 983
Reputation: 984
As ProGamer Suggested,
First
save you
My.Settings.MDF
String = None
Second
Edit your code as follows:
Private Sub FormLoad(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Settings.MDF = "None" Then
txtMDF.Text = Application.StartupPath + "\MyDB.mdf"
Else
txtMDF.Text = My.Settings.MDF
End If
txtMDF.Text = My.Settings.MDF
End Sub
Third
Add the following code to YourFormClose_Event
Private Sub FormClosing(sender As Object, e As CancelEventArgs) Handles Me.Closing
My.Settings.MDF = txtMDF.Text
My.Settings.Save()
End Sub
And NOTE that you should select "User" from 'Scope Drop Down' in the Settings for MDF instead of "Application" or else My.Settings.Save() will not work and it will remain "None"
Example:
Upvotes: 2