locked
Query sqlite c# windows store RRS feed

  • Question

  • Hello people, 

    I have this problem, in my app windows store c# I use sqlite to show data.

    But in query on table 

     
                        var consultaAluno = db.Query<Pessoa>("SELECT Pessoa.Nome FROM Pessoa).First();

    and i can show in textblock

     txtAlunosResult.Text = consultaAluno.Nome;

    it's work, but just show the first data. I use de method Last() in query but just show de last data. How to show all data in table pessoa? 

    thanks

    Wednesday, November 27, 2013 11:12 AM

Answers

  • Hello Aurelien Mota, 

    you need to remove .First() from code. So you get list of Nome, than you use foreach for get one by one than show in list. Like that :

      var consultaAluno = db.Query<Pessoa>("SELECT Pessoa.Nome FROM Pessoa);
    
    ObservableCollection<string> ab = new ObservableCollection<string>();
    foreach(var a in consultaAluno)
    {
    ab.Add(a.Nome);
    }
    
    //bind to listbox or listview
    listview1.ItemsSource = ab;
    • Marked as answer by Aurelien Mota Wednesday, November 27, 2013 12:54 PM
    Wednesday, November 27, 2013 11:33 AM

All replies

  • The .First() or .Last() will only take one record. This should get all the records.

    var consultaAluno = db.Query<Pessoa>("SELECT Pessoa.Nome FROM Pessoa");

    You would have to use a listbox to show all the records.

    Wednesday, November 27, 2013 11:26 AM
  • Hello Aurelien Mota, 

    you need to remove .First() from code. So you get list of Nome, than you use foreach for get one by one than show in list. Like that :

      var consultaAluno = db.Query<Pessoa>("SELECT Pessoa.Nome FROM Pessoa);
    
    ObservableCollection<string> ab = new ObservableCollection<string>();
    foreach(var a in consultaAluno)
    {
    ab.Add(a.Nome);
    }
    
    //bind to listbox or listview
    listview1.ItemsSource = ab;
    • Marked as answer by Aurelien Mota Wednesday, November 27, 2013 12:54 PM
    Wednesday, November 27, 2013 11:33 AM