[英]How to get the last record
I want to get my last record in the table I use this code but it returns nothing 我想使用该代码获取表中的最后一条记录,但未返回任何内容
var a = new DataClasses1DataContext();
var student = db.tbl_farmers.OrderByDescending(s => s.id).FirstOrDefault();
dataGridView1.DataSource = student;
Try this 尝试这个
var a = new DataClasses1DataContext();
var student = db.tbl_farmers.OrderByDescending(s => s.id).Take(1);
dataGridView1.DataSource = student;ode here
In LINQ we achieve the same thing with the help of OrderByDescending function and Take function. 在LINQ中,我们借助于OrderByDescending函数和Take函数来实现相同的目的。
var qry = db.ObjectCollection
.Where(m => m.<field> == data)
.OrderByDescending(m => m.<field>)
.Take(n);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.