SQLite - loop through records

Yusuf 791 Reputation points
2022-04-09T10:58:08.953+00:00

Hi,
How can I loop through sqlite table, I can view
Data in ListView using xaml, but I want to deal with each row individually , example display each BookTitle in displayAlert.

using System;
using System.IO;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace App1
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {
        string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "database.db3");
        public MainPage()
        {
            InitializeComponent();
        }

        protected override async void OnAppearing()
        {
              listView.ItemsSource = await App.Database.GetBooksAaync();
        }
    }
}
Developer technologies .NET Xamarin
SQL Server Other
Developer technologies C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yusuf 791 Reputation points
    2022-04-10T10:02:59.997+00:00
    0 comments No comments

  2. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-04-11T02:22:14.503+00:00

    Hello,

    As the documentation you found, you can use the following steps for looping each record:

    Step1: Get the records from a table in database.

    Step2: Use foreach to loop each record.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.