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.
精彩评论