Search code examples
sqlitewindows-phone

How to loop through records?


So i want to loop trough all records that has same Barcode (its not PK), compare price of each record and take the one with lowest price. How exactly i loop trough records and then check each?

  var tp = dbConn.Query<Products>("select * from Products where Barcode='" + TextBoxB.Text + "'").FirstOrDefault();

         if(int.Parse(tp.Price)<lowest_price)
         {
             lowest_price = int.Parse(tp.Cena);
         }

How do i wrap that in for loop that will loop trough each record that match the criteria. This way it only gets first record obviously. This is maybe stupid question but i have no experience in Databases


Solution

  • ToList will get all the records that you can loop through

    var tp = dbConn.Query<Products>("select * from Products where Barcode='" + TextBoxB.Text + "'").ToList();