Click here to Skip to main content
15,887,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im working on a winform application using c#.
Im using access database for it.
I want to make a browse button to select my old db, then after click a button, copy all of its tables(selected database) and data to my project new database and dosnt remove tables that exist in main database.
1.I wanna know how to make a connection string to selected old database(that I selected with browse)
2.how to make query to copy all of its tables and data to my new database(directory database).
**all tables have the same name and columns.
thanks

What I have tried:

I cant figure it out how to make a connection string to browsed database and how to write a query to copy its tables to another database
Posted
Updated 12-Oct-22 17:56pm
Comments
Sandeep Mewara 12-Oct-22 23:01pm    
Google has ample information around this. Did you look at them? Anything specific you are stuck with?

1 solution

Quote:
1.I wanna know how to make a connection string to selected old database(that I selected with browse)
Simple SQL Connection String Creation[^] - use the "Provider" tab to select the Access DB engine and it works for Access DBs as well.
Then you can import that string into your app, and replace the DB path part with the path the user selected.
Quote:
2.how to make query to copy all of its tables and data to my new database(directory database).
**all tables have the same name and columns.

c# copy table from one database to another access - Google Search[^]


Quote:
is not gonna work cuz he wrote the address "Z:\Docs\first.accdb"
I dont have a address

:sigh:

You replace the path in your example: "Z:\Docs\first.accdb" with a unique marker: "%PATH%" say.
string conPattern =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%PATH%";


You browse.
It returns a path string.

You replace the marker with the string he browsed to.
 
Share this answer
 
v2
Comments
Ehsan Nabavi 13-Oct-22 19:06pm    
this string "sing System.Data.OleDb;
<...>
string ConnString =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Docs\first.accdb";
OleDbConnection conn = new OleDbConnection(ConnString);"
is not gonna work cuz he wrote the address "Z:\Docs\first.accdb"
I dont have a address
I can browse and pick old database file from everywhere in my hard drive
now I wanna connect to db1 file that I selected with browse.
after that make another connection to my main db and copy tables from db1 to main db.
OriginalGriff 14-Oct-22 0:45am    
Answer updated.

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