开发者

How to return datatable using Take() using C#

I have a function that returns a datatable, I added a code that will sort the datatable using dataview and should return Top 10 rows from a sorted dataview.

DataView dvDt = dtData.DefaultView;
dvDt.Sort = "Value DESC"
var vlist = dvDt.ToTable().AsEnumerable().Take(10);

I wa开发者_如何学Pythonnt to know how can I make sure I get the datatable as return item. How to convert "vlist" to datatable?

I use: C# and .net 3.5 framework.


You can use DataTableExtensions.CopyToDataTable:

var table = vlist.CopyToDataTable();


You will need to create an instance of a new DataTable, add the appropriate columns to it, and then iterate vlist and populate the data table via the NewRow method. There are no built-in methods to do this for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜