Click here to Skip to main content
15,885,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to change final database files path reading and setting them from access to codes necessary field?
Also I want to set this paths in win form and save it in access

svo_dirInf = new DirectoryInfo(Environment.CurrentDirectory);
svo_dirDBFiles = svo_dirInf.FullName;

svo_dirDB = svo_dirDBFiles + "DB_Files\\Allfiles.mdb";
svo_dirOS = svo_dirDBFiles + "OS";
svo_dirDBFiles = svo_dirDBFiles + "DB_Files";

and I have access table like this

Name Value
OS D:\Server\Day_OS
DB_Server D:\Server\DB_Files
OS_Server D:\Server\OS
svo_File D:\Server\OS\20

I want read name and set value

Also I have FolderBrowserDialog in new opening form where in textboxes I want to set new Paths for files
So the current directory will be changed the path which I set in new form

What I have tried:

to change final database files path
Posted
Updated 18-May-20 1:28am
v4
Comments
OriginalGriff 18-May-20 7:08am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. And what you have typed means nothing to me without context.

Try explaining exactly what you have as inputs, and exactly what you expect to get as outputs - that may help.

Use the "Improve question" widget to edit your question and provide better information.

 
Share this answer
 
Comments
Member 14734812 18-May-20 7:37am    
Thanks
You should build your paths using the Path.Combine method. It will automatically take care of path separators for you.
C#
string basePath = @"C:\ProgramData";

// appDir == @"C:\ProgramData\MyApp"
string appDir = Path.Combine(basePath, "MyApp");

// dbDir == @"C:\ProgramData\MyApp\DB"
string dbDir = Path.Combine(appDir, "DB");

// osDir == @"C:\ProgramData\MyApp\OS"
string osDir = Path.Combine(appDir, "OS");

// dbFile == @"C:\ProgramData\MyApp\DB\Allfiles.mdb"
string dbFile = Path.Combine(dbDir, "Allfiles.mdb");

Also note the extra @ in front of the opening double-quote for the string declaration. It tells the compiler that backslash should not be interpreted as an escape character as it would normally do, but rather as the literal backslash character itself. It allows for specifying paths without the need to double the backslashes:
C#
string basePath = @"C:\ProgramData";
// is equivalent to
string basePath = "C:\\ProgramData";


Regarding the database-storage part, you can save any path, or part of a path, as a string.

Finally, if you want to change the path of the database in the application, you have to do it before connecting to the database. If there is an active connection, you would have to close it, change the path, and then open the connection on the new database.
 
Share this answer
 
Comments
Member 14734812 18-May-20 7:30am    
Ok thanks but I want to use FolderBrowserDialog in my new Form where I set value in textboxes and then read this and update access table
phil.o 18-May-20 7:37am    
What is the problem?
Member 14734812 18-May-20 7:35am    
finally I want to transform my code like I open my form and select any directory I want and after all this when I use programm files will be in my selected directory
phil.o 18-May-20 7:37am    
What prevents you from doing that?
Member 14734812 18-May-20 7:41am    
First of all I don't know how to read access table's fields and during this process give value for example OS = D:\Server\Day_OS

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900