Changing Access Database File during runtime

Core

Registered User.
Local time
Today, 06:30
Joined
May 27, 2008
Messages
79
Hi I am really new to vb.net database programming so bear with ;)

I have made a simple front end displaying data from an access table. I want the user to be able to locate the file using a dialog however as the access file could be anywhere on the computer.

I have created a menu strip that the user can use open a dialog window and locate a folder.

How do I code VB to change where it looks for the access database file?

Hope that makes sense.
 
OpenFileDialog1.InitialDirectory = "C:\temp"

allows you to set the the default directory used by the open/save file dialog.

By default I believe the dialogues should point to MyDocuments
 
that's not a big deal..any one can do that..but how to change access database while runtime..that means i want change connection string in app.config/web.config...for example i build the project and i gave to the client..at that time user can change the different databases he need.

if any body have an idea please tell me how to write..

i have some code it's not working

// Get the application configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);

// Get the current connection strings count.
int connStrCnt =
ConfigurationManager.ConnectionStrings.Count;

// Create the connection string name.
string csName =
"ConnStr" + connStrCnt.ToString();

// Create a connection string element and
// save it to the configuration file.

// Create a connection string element.
ConnectionStringSettings csSettings =
new ConnectionStringSettings(csName, @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\---.mdb;Persist Security Info=True;" +
"Jet OLEDBdatabase Password=--", "System.Data.OleDb");
// Get the connection strings section.
ConnectionStringsSection csSection =
(System.Configuration.ConnectionStringsSection)config.ConnectionStrings;

// Add the new element.

csSection.ConnectionStrings.Add(csSettings);

// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified,true);


.:(
 

Users who are viewing this thread

Back
Top Bottom