3

This doesn't work

DataTable myNewTable = myDataTable.Select("Name <> 'n/a'").CopyToDataTable();

myDataTable has a row named Name. I would like to select the rows from this table where Name is not equal to "n/a". It selects but still am missing the null values i need the null values too.

Can anyone help?

4

4 回答 4

19

Try this

myDataTable.Select("[Name] is NULL OR [Name] <> 'n/a'" )

Edit: Relevant sources:

于 2013-05-27T05:55:17.837 回答
4

Try out Following:

DataRow rows = DataTable.Select("[Name]<>'n/a'")

For Null check in This:

DataRow rows =  DataTable.Select("[Name] <> 'n/a' OR [Name] is NULL" )
于 2013-05-27T05:52:44.140 回答
2

The way to check for null is to check for it:

DataRow[] myResultSet = myDataTable.Select("[COLUMN NAME] is null");

You can use and and or in the Select statement.

于 2013-05-27T05:56:58.463 回答
2

try this:

var result = from r in myDataTable.AsEnumerable()  
            where r.Field<string>("Name") != "n/a" &&  
                  r.Field<string>("Name") != "" select r;  
DataTable dtResult = result.CopyToDataTable();  
于 2013-05-27T05:58:33.647 回答