Why do you select a table from sql-server which you first need to filter at all? Can't you add this to the WHERE
-clause?
With .NET 3.5 you should be able to use Linq-To-DataSet
which is much more powerful and readable:
DataTable parent = GetTable();
DataTable child = parent.AsEnumerable()
.Where(row => row.Field<int>("cols") != -1)
.CopyToDataTable();
If you want to use DataTable.Select
anyway you have to use <>
instead of !=
.
DataRow[] filtered = parent.Select("cols <> -1");
Have a look here for the expression syntax: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(v=vs.110).aspx
When you create comparison expressions, the following operators are allowed:
<
>
<=
>=
<>
=
IN
LIKE
The following arithmetic operators are also supported in expressions:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulus)