Copy selected data from DataTable to another DataTable

I want to select some data from a datatable and copy it to another data table. I found the answer in one question - How to query a DataTable in memory to populate another data table

DataTable table = GetDataTableResults(); DataTable results = table.Select("SomeIntColumn > 0").CopyToDataTable(); 

This code does not work and causes an error -

 'System.Array' does not contain a definition for 'CopyToDataTable' and no extension method 'CopyToDataTable' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) 

I am using visual studio 2008 and .net 3.5.

+2
source share
2 answers

Make sure you have the correct links. In this you need System.Data.DataSetExtensions Assembly and System.Data Namespace. The following link should help ...

http://msdn.microsoft.com/en-us/library/bb396189(v=vs.110).aspx

Good luck

EDIT: Screenshot ...

enter image description here

+3
source

You can always simply skip the array of DataRow objects returned from Select() and import them into a new data table, for example:

 DataTable table = GetDataTableResults(); DataTable results; DataRow[] rowArray = table.Select("SomeIntColumn > 0"); foreach (DataRow row in rowArray) { results.ImportRow(row); } 
+1
source

Source: https://habr.com/ru/post/895336/


All Articles