2

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

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

This code does not work and causes the 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 Answers 2

4

Make sure you have the right references. 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 of Reference...

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

Does not work. I tried that link before posting the question. I cannot find the System.Data.DataSetExtensions.dll in my references menu.
I see it in my menu. I think this library is available only in .NET 3.5 and above
I still cannot see it in my menu. Also, can you post a bigger image please ? I tried clicking yours, but it wont become big. Thanks.
Updated the image. Any better?
The following link should walk you through the process changing the target .NET framework version...msdn.microsoft.com/en-us/library/vstudio/bb398202(v=vs.90).aspx
|
1

You can always just loop through the array of DataRow objects returned from Select() and import them into the new data table, like this:

DataTable table = GetDataTableResults();
DataTable results;

DataRow[] rowArray = table.Select("SomeIntColumn > 0");

foreach (DataRow row in rowArray) 
{
    results.ImportRow(row);
}

1 Comment

Thanks for showing me an alternate way. But, I prefer to do it without using rows.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.