SQLite 为 Windows WPF 桌面创建数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27196605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:44:52  来源:igfitidea点击:

SQLite create database for Windows WPF Desktop

c#wpfsqlitesqlite-net

提问by Paul Meems

I have a WPF Desktop application which I want to connect to a SQLite database. I've read this tutorial about sqlite-net. I've installed it using NuGet.

我有一个 WPF 桌面应用程序,我想将它连接到 SQLite 数据库。我已经阅读了有关sqlite-net 的本教程。我已经使用 NuGet 安装了它。

When I start my application I want to check if the db file exists and if not create it, but sqlite-net doesn't have a CreateDatabase option. It looks like it assumes the file is pre-created.

当我启动我的应用程序时,我想检查 db 文件是否存在,如果不创建它,但 sqlite-net 没有 CreateDatabase 选项。看起来它假设文件是​​预先创建的。

I've also installed System.Data.SQLite (x86/x64) using NuGet, but I still can't find a method to create a database through C# code.

我还使用 NuGet 安装了 System.Data.SQLite (x86/x64),但我仍然找不到通过 C# 代码创建数据库的方法。

Can anybody give me some pointers so I can continue?

任何人都可以给我一些指示,以便我可以继续吗?

Thanks.

谢谢。

回答by Markus Palme

sqlite-net creates the database file for you when you call the CreateTablemethod (and it doesn't already exist). Take a look at the getting started guidefor a full example:

当您调用该CreateTable方法时,sqlite-net 会为您创建数据库文件(它尚不存在)。查看入门指南获取完整示例:

var db = new SQLiteConnection("mydatabase.db");
db.CreateTable<Person>();