locked
fetch data from sqlite into listview RRS feed

  • Question

  • How to fetch and filter data from sqlite data base into the list view control???

    Sunday, September 15, 2013 9:25 AM

All replies

  • Hello H & J Developer,

    Show this link: windows-8-storing-data-with-sqlite

    Sunday, September 15, 2013 9:40 AM
  • i have a Gridview on firstpage which displays the chapters name.I want whenever i click on any gridviewitem i.e. chapter , on the next page the list of topics related to that chapter should be displayed in the Listview.I am using a sqite database "databaseprograms".

    pageTitle is the chapter's name.

    The following code will fetch all the fields related to that chapter.However i want only Topics to b displayed in the listview .

     string dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Programs.sqlite");
                    SQLite.SQLiteConnection dbcon = new SQLite.SQLiteConnection(dbpath);
                    var records = dbcon.Table<databaseprograms>().Where(temp = temp.ProgramChapter == pageTitle);
                    var result = await records.ToListasynch();

    foreach (var item in result)
                    {
                        ListViewItem lvi = new ListViewItem();
                        listviewprogram.Items.Add(lvi);
                    }

    Sunday, September 15, 2013 10:51 AM
  • Hello H & J Developers,

    Try this:

    SQLiteAsyncConnection conn2 = new SQLiteAsyncConnection(dbpath);

    var records = await conn.QueryAsync<databaseprograms>(YOUR QUERY);
    ListViewItem lvi = new ListViewItem();
    foreach(var a in records)
    {
     listviewprogram.Items.Add(lvi);
    }
    
    //click on listviewitem
    private async void listview1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
    {
    this.Frame.Navigate(typeof(yourpagename),pass the value to another page);
    }

    Monday, September 16, 2013 4:26 AM
  • Hi,

    In your GridView SelectionChanged event, you can get the object which chapter name is the selectItem(pageTitle). And then pass the object to the ListView page.

    Try to code like below:

    string dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Programs.sqlite");
                SQLite.SQLiteConnection dbcon = new SQLite.SQLiteConnection(dbpath);
                var records = dbcon.Table<databaseprograms>().Where(temp => temp.ProgramChapter == pageTitle);
                this.Frame.Navigate(typeof(listviewpage), records);

    Next in listviewpage OnNavigatedTo event you can get the object and code like this:

     protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                var records = e.Parameter as databaseprograms;
                foreach (var a in records)
                {
                    listview.Items.Add(a.topic.ToString());
                }
            }

    Best Wishes!





    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Anne Jing Tuesday, September 17, 2013 6:54 AM from
    • Marked as answer by Anne Jing Friday, September 20, 2013 7:00 AM
    • Unmarked as answer by H and J Developers Sunday, September 22, 2013 6:41 AM
    Tuesday, September 17, 2013 6:54 AM
  • even this code is not working.Records is not fetching any data.

    var records = dbcon.Table<databaseprograms>().Where(temp => temp.ProgramChapter==pageTitle.toString());

    Sunday, September 22, 2013 6:40 AM
  • the query is not fetching any data.

    var records = dbcon.Table<databaseprograms>().Where(temp => temp.ProgramChapter==pageTitle.toString());

    Sunday, September 22, 2013 6:41 AM
  • Hi,

    You can upload your project in the skyDrive and share a link in the forum.I think the code is correct,may be any

    other problems exist in your project.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 1:44 AM