[英]Create new SQLite database on WinRT?
我想從我的 WinRT 應用程序中的 C# 代碼創建一個新數據庫。 我在網上搜索了一下,這樣做的方法似乎是 SQLiteConnection.CreateFile() 方法。 但是,該方法在 SQLite 命名空間中不存在,至少在 WinRT 版本中是這樣。 我使用 NuGet 包名稱“sqlite-net”安裝了 SQLite,並將 sqlite3.dll 包含到我的項目中。 我確實看到了正確的方法,如 CreateTable()、Query() 等,但沒有看到 CreateFile()。 它在哪里? 或者 WinRT 包是否使用不同的方法從代碼創建數據庫文件?
var db = new SQLiteConnection(databasePath, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite);
我是怎么做到的。
Microsoft 提供了一個簡單示例的時間之一:
https://docs.microsoft.com/en-us/windows/uwp/data-access/sqlite-databases
await ApplicationData.Current.LocalFolder.CreateFileAsync("sqliteSample.db", CreationCollisionOption.OpenIfExists);
string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
using (SqliteConnection db =
new SqliteConnection($"Filename={dbpath}"))
{
db.Open();
String tableCommand = "CREATE TABLE IF NOT " +
"EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
"Text_Entry NVARCHAR(2048) NULL)";
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
createTable.ExecuteReader();
因為取決於您如何將 sqlite 添加到 UWP 項目,在 2021 年沒有 createfile() 仍然是一個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.