首页 > 解决方案 > SQLite Xamarin.forms 不返回保存的数据

问题描述

我坚持使用 Xamarin.Forms SQLite。

我使用这个 NuGet 包:sqlite-net-pcl

我的 SQLITE 表

我想使用以下代码将表中的数据保存到变量中

        SQLiteConnection myconnection = new SQLiteConnection(Constants.DatabasePath);

        SQLiteCommand cmd = new SQLiteCommand(myconnection);
        myconnection.CreateTable<Modul>();

        var Mods = myconnection.Query<Modul>("SELECT * FROM Modul");

Mods 返回 = Count=0; 但我已经保存了数据。点击这里

我的模块类:MoulID 在顶部有主键 [Primarykey]...

   public int ModulID { get; set; }

    public string Modul_Name { get; set; }

我将从这里包含我现有的数据库

与这堂课

公开课{

   public const string DatabaseFilename = "VocalDB.db";



    public static string DatabasePath
    {
        get
        {
            var basePath = "D:/C#-Projets/Vocabul/Vocabul/Vocabul/DataBase/";
            return Path.Combine(basePath, DatabaseFilename);
        }
    }

}

标签: xamarin.formssqlite-net

解决方案


在您的代码中,您创建表然后执行查询...我认为创建表后该表是空的。

  myconnection.CreateTable<Modul>();

        var Mods = myconnection.Query<Modul>("SELECT * FROM Modul");

推荐阅读