Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Casting DataView.ToTable c#

$
0
0

I want to create a small, sorted, strongly-typed DataTable from a strongly-typed source DataTable.  The most straightforward way I know to create a sorted DataTable is to create a DataView, assign a Sort value, and convert the DataView back to a DataTable.  That works fine.  What doesn't work is the cast back to the original type of the source DataTable.  I suspect the trip through the DataView is losing info that enables the strong typing, but I want to make sure I'm not missing something. Sample code is below.

Thanks for any help you can provide.  Steve

DataView dvSource = new DataView(dtSource);
dvSource.Sort = dtSource.MyColumn.ColumnName + " DESC";
MyDataSet.SourceDataTable dtSorted = (MyDataSet.SourceDataTable)dvSource.ToTable();



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>