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.
    <br /> using System;<br /> using Android.App;<br /> using Android.Content;<br /> using Android.Runtime;<br /> using Android.Views;<br /> using Android.Widget;<br /> using Android.OS;<br /> using System.Threading;<br /> using Android.Webkit;<br /> using System.IO;<br /> using SQLite;<br /> using System.Collections.Generic;<br /> using System.Linq;</p> <p>namespace OptimizingFoodPurchasedCostApp<br /> {<br /> [Activity(Label = "MembersActivity")]<br /> public class MembersActivity : Activity<br /> {<br /> protected override void OnCreate(Bundle savedInstanceState)<br /> {<br /> base.OnCreate(savedInstanceState);<br /> SetContentView(Resource.Layout.MemberViewPage);</p> <pre><code> 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.