We're creating an application that stores data in a number of tables using an SQL Server Compact .sdf
file.
When the program starts, we want to present the user the option of working from an existing database file that already contains data, or create a new empty database file. We've created the .sdf
file using the database explorer in Visual Studio, so I presume it's being stored with the bin files by default.
Two questions:
How do we use the OpenFileDialog
to allow the user to select a database and modify the data connection accordingly?
When the user decides to start with a new database, will the program remember the database structure we created with the database explorer, or do we have to recreate the tables, fields and connections from scratch in the program?
ThanX!
Unless you intentionally want users to be able to access DB files from any arbitrary location on their computer, you'd be better off storing the DB files in an application directory and letting users pick the DB from a simple ListView (which you would populate by iterating through all the DB files in your application's data directory or sub-directory).
For your second question, you should create a template database file with the correct tables, fields etc. but no data, and embed this as a resource in your application. To create a new database for the user, you would copy this resource to an actual file location (with the new DB's file name).