如何循环记录?
How to loop through records?
所以我想遍历所有具有相同条形码(不是 PK)的记录,比较每条记录的价格并选择价格最低的记录。我究竟如何循环记录然后检查每个记录?
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);
}
我如何将它包装在 for 循环中,循环遍历符合条件的每条记录。这样它显然只能获得第一条记录。
这可能是个愚蠢的问题,但我没有数据库方面的经验
ToList 将获取您可以循环遍历的所有记录
var tp = dbConn.Query<Products>("select * from Products where Barcode='" + TextBoxB.Text + "'").ToList();
所以我想遍历所有具有相同条形码(不是 PK)的记录,比较每条记录的价格并选择价格最低的记录。我究竟如何循环记录然后检查每个记录?
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);
}
我如何将它包装在 for 循环中,循环遍历符合条件的每条记录。这样它显然只能获得第一条记录。 这可能是个愚蠢的问题,但我没有数据库方面的经验
ToList 将获取您可以循环遍历的所有记录
var tp = dbConn.Query<Products>("select * from Products where Barcode='" + TextBoxB.Text + "'").ToList();