how can display SQLite database table data listView.

I develop the Xamarin Android App. But I have a problem, how can display SQLite database table data in listView. And also, the table has many data. plz, give me some advice how can solve this problem.

Best Answer

Answers

  • MabroukMabrouk USMember ✭✭✭

    Hi @SampathTharanga ,

    Take a look here. You will find what you Need.

    I hope that helps,
    Mabrouk.

  • SampathTharangaSampathTharanga USMember ✭✭
    edited August 2017

    @Mabrouk I refer your link. but I can't solve my problem. I refer this one. The code is correct but does not work at runtime event. This is my code section, please check and give me some advice.

    using System;
    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;
    using System.Threading;
    using Android.Webkit;
    using System.IO;
    using SQLite;
    using System.Collections.Generic;
    using System.Linq;

    namespace OptimizingFoodPurchasedCostApp
    {
    [Activity(Label = "MembersActivity")]
    public class MembersActivity : Activity
    {
    protected override void OnCreate(Bundle savedInstanceState)
    {
    base.OnCreate(savedInstanceState);
    SetContentView(Resource.Layout.MemberViewPage);

            string dbpath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "appdb.db3");//Create new database
            var db = new SQLiteConnection(dbpath);
            var data = db.Table<MembersTable>();//Call Table
            //var data1 = new List<string>();
            //var data1 = db.Query<MembersTable>("SELECT * FROM MembersTable");
    
            foreach (var listing in data)
            {
                var from = new string[]
                {
                    listing.name + "   -   " + listing.gender
                };
    
                ListView listtable = (ListView)FindViewById(Resource.Id.listViewMember);
                listtable.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, from);
            }
        }
    
    }
    

    }

    And also click app menu item link, does not load database table data. Then comes error,

    But have the "MembersTable" table. And also members register and login are correctly working.

  • SampathTharangaSampathTharanga USMember ✭✭
    edited August 2017 Accepted Answer
Sign In or Register to comment.