使用 Dataview.RowFilter 从 SomeTable 中选择 TOP 5 *?
我需要从缓存的 Dataview 对象中选择最近的 5 行,有什么办法可以做到这一点吗?
我已经尝试过,但索引器数据列是空的。 :
public static DataView getLatestFourActive()
{
DataTable productDataTable = getAll().ToTable();
DataColumn ExpressionColumn = new DataColumn("Indexer",typeof(System.Int32));
ExpressionColumn.Unique = true;
ExpressionColumn.AutoIncrement = true;
ExpressionColumn.AllowDBNull = false;
ExpressionColumn.AutoIncrementSeed = 0;
ExpressionColumn.AutoIncrementStep = 1;
productDataTable.Columns.Add(ExpressionColumn);
DataView productFilteredView = productDataTable.DefaultView;
productFilteredView.RowFilter = "isActive=1 and Indexer<4";
return productFilteredView;
}
getAll() 返回缓存的 DataView
谢谢
I need to select 5 most recent rows from cached Dataview object, is there any way to do that?
I've tried but Indexer DataColumn is empty. :
public static DataView getLatestFourActive()
{
DataTable productDataTable = getAll().ToTable();
DataColumn ExpressionColumn = new DataColumn("Indexer",typeof(System.Int32));
ExpressionColumn.Unique = true;
ExpressionColumn.AutoIncrement = true;
ExpressionColumn.AllowDBNull = false;
ExpressionColumn.AutoIncrementSeed = 0;
ExpressionColumn.AutoIncrementStep = 1;
productDataTable.Columns.Add(ExpressionColumn);
DataView productFilteredView = productDataTable.DefaultView;
productFilteredView.RowFilter = "isActive=1 and Indexer<4";
return productFilteredView;
}
getAll() returns cached DataView
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 this 中遇到了上面相同的示例文章,但最后一篇文章说提供的代码不起作用。
但是,本文有一个确实有效的解决方案,所以这里是您可以使用的代码使用:
I encountered the same sample above in this article, but the last post says the provided code doesn't work.
However, this article has a solution that does work, so here's the code you could use: