Xamarin Form Sqlite Connection:找不到方法:int SQLite.SQLiteConnection.CreateTable(SQLite.CreateFlags)

问题描述 投票:0回答:2

构建成功,但是涉及到此方法时,它将引发异常。当我在NuGet软件包中更新新软件包时,发生了这种情况。

public static string checkToken()
        {
            string token1 = "";
            try
            {
                SQLiteConnection db = DependencyService.Get<SQLiteInterface>().GetConnection();
                db.CreateTable<Token>();
            Token t = db.Table<Token>().FirstOrDefault();
            if (t != null)
            {
                DateTime dt = t.timeCreated;
                DateTime tmp = DateTime.Now;

                double diff = (tmp - dt).TotalMinutes;
                if (diff > 60.0 || App.IsUserLoggedIn == false)
                {
                    token1 = "expired";
                    db.Delete(t);
                }
                else
                {
                    token1 = t.token;
                }
            }
        }
        catch (Exception e)
        {
            e.ToString();
        }
        return token1;
    }

这里是图像。

enter image description here

UPDATED:

此软件包来自.Droidenter image description here

此包装来自便携式enter image description here

sqlite xamarin xamarin.forms
2个回答
0
投票

这很烦人,但是您很有可能必须删除所有这些软件包并重新安装它们。尝试删除它们并添加以下软件包

您的本机项目中的SQLitePCLRaw.bundle_green版本1.1.2(不在PCL中)

您的本机项目中的SQLitePCLRaw.core版本1.1.2(不在PCL中)

SQLitePCLRaw.lib.e_sqlite3.android版本1.1.2

SQLitePCLRaw.provider.e_sqlite3.android版本1.1.2

SQLitePCLRaw.provider.sqlite3.ios_unified版本1.1.2

然后在创建数据库时,使用以下代码作为路径对其进行初始化:

string path = System.IO.Path.Combine(System.Environment
            .GetFolderPath(System.Environment.SpecialFolder.Personal), "localstore.db");

OR

如果不起作用,请全部删除,并仅添加以下所有项目

https://www.nuget.org/packages/sqlite-net-pcl/

我希望这会有所帮助


0
投票

正如Janwilx72所说,您需要安装Nuget for Pcl and Platforms的sqlite-net-pcl软件包。不需要您提供的软件包。

enter image description here

然后您可以使用SQLiteConnection.CreateTable()且没有问题。

我在github上为Android做了一个示例,您可以看一下:

https://github.com/CherryBu/sqliteapp

如果您想在ios或其他平台上执行此操作,可以看一下本文:

https://dzone.com/articles/register-and-login-using-sqlite-in-xamarinforms

https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/july/xamarin-working-with-local-databases-in-xamarin-forms-using-sqlite

© www.soinside.com 2019 - 2024. All rights reserved.