简体   繁体   English

用户可选的SQL Server Compact数据库

[英]User selectable SQL Server Compact database

We're creating an application that stores data in a number of tables using an SQL Server Compact .sdf file. 我们正在创建一个应用程序,它使用SQL Server Compact .sdf文件将数据存储在多个表中。

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. 我们使用Visual Studio中的数据库资源管理器创建了.sdf文件,因此我假设它默认存储在bin文件中。

Two questions: 两个问题:

  • How do we use the OpenFileDialog to allow the user to select a database and modify the data connection accordingly? 我们如何使用OpenFileDialog来允许用户选择数据库并相应地修改数据连接?

  • 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). 除非您故意希望用户能够从他们计算机上的任意位置访问数据库文件,否则最好将数据库文件存储在应用程序目录中,并让用户从简单的ListView中选择数据库(您将填充遍历应用程序的数据目录或子目录中的所有DB文件。

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). 要为用户创建新数据库,可以将此资源复制到实际文件位置(使用新DB的文件名)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM