how can display SQLite database table data listView. RRS feed

  • Question

  • User311987 posted

    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.

    Thursday, August 10, 2017 12:11 PM


All replies

  • User192947 posted

    Hi @SampathTharanga ,

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

    I hope that helps, Mabrouk.

    Thursday, August 10, 2017 1:34 PM
  • User311987 posted

    @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.

    Friday, August 11, 2017 2:48 AM
  • User311987 posted

    This is the solution for my problem. Thanks @Mabrouk for your advice.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, August 15, 2017 10:58 AM