windows应用程序中的SQlite连接中出现表映射无法执行错误

本文关键字:映射 执行 错误 应用程序 SQlite 连接 windows | 更新日期: 2023-09-27 17:59:16

当我将应用程序与SQLite数据库连接时。以下异常引发。

 An exception of type 'SQLite.SQLiteException' occurred in
 Scrap_Book.Windows.exe but was not handled in user code
 Additional information: no such table: CONTENT

我在SqLite经理的帮助下制作了这张桌子——一个烤的mozila firefox。请帮我怎么解决这个问题。

          var dbpath =    Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "MYSCRAPBOOK.sqlite");
        using (var db = new SQLite.SQLiteConnection(dbpath))
            db.Insert(new CONTENT()
            {
                STICKERS=snodesticker
            });

             db.Commit();
            db.Dispose();
            db.Close();
            var line = new MessageDialog("Records Inserted");
            await line.ShowAsync();

windows应用程序中的SQlite连接中出现表映射无法执行错误

根据来自异常的消息,您尚未创建CONTENT表。

所以,我想您需要在插入数据之前创建表。

public static string DB_NAME = "ContactsManager.sqlite";
public static string DB_PATH = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, DB_NAME));//DataBase Name 
private async Task<bool> CheckFileExistsAsync(string fileName)
{
    try
    {
        var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
        return true;
    }
    catch
    {
    }
    return false;
}
if (!(await CheckFileExistsAsync(DB_NAME)))
{
    using (var db = new SQLiteConnection(DB_PATH))
    {
        db.CreateTable<CONTENT>();
    }
}