SQLite - loop through records

Yusuf 731 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();
        }
    }
}
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,316 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,122 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,527 questions
0 comments No comments
{count} votes

2 answers

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

  2. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 38,066 Reputation points Microsoft Vendor
    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