【问题标题】:I found a xamarin forms project which uses Azure, I want to do the same thing using SQLite我找到了一个使用 Azure 的 xamarin forms 项目,我想使用 SQLite 做同样的事情
【发布时间】:2019-08-06 15:45:52
【问题描述】:

该项目是一个使用 SqLite 的 xamarin 形式的测验应用程序,在代码中需要有一种方法来加载问题,我将展示它们在 Azure 中是如何做到的,我需要在 SqLite 中做同样的事情。我还包含一个指向使用 Azure 的 xamarin 测验的源代码的链接。 [1]:https://github.com/garudaslap/xamarinquiz

    public async Task LoadQuestions()
    {
        IsLoading = true;
        MobileServiceClient client = AppSettings.MobileService;

        IMobileServiceTable<XamarinQuiz> xamarinQuizTable = 
        client.GetTable<XamarinQuiz>();

        try
        {
            QuestionList = await xamarinQuizTable.ToListAsync();
        }
        catch (Exception exc)
        {
        }


        IsLoading = false;
        ChooseNewQuestion();
    }

【问题讨论】:

    标签: sqlite-net-pcl


    【解决方案1】:

    您可以将 SQLite 与此插件一起使用:

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/databases

    那么你的代码会是这样的:

    public async Task LoadQuestions()
    {
        IsLoading = true;
        SQLiteAsyncConnection connection = new SQLiteAsyncConnection(dbPath);
    
        // if you need to create the table
        connection.CreateTableAsync<XamarinQuiz>().Wait();
    
        try
        {
            QuestionList = await database.Table<XamarinQuiz>().ToListAsync();
        }
        catch (Exception exc)
        {
        }
    
    
        IsLoading = false;
        ChooseNewQuestion();
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-18
      • 2020-09-08
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多