Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

Im trying to filter a datatable, i´m using this and it works:
C#
DataRow[] rowsTarget = dt3.Select(string.Format("CodigoKitDC={0}", row["Items"]));
but now i need to have the rest of the data,

how can i make a string format with the different, something like this:
C#
string.Format("CodigoKitDC != {0}", row["Items"]));
but it not Works.help please

What I have tried:

string.Format("CodigoKitDC != {0}", row["Items"]));
string.Format("CodigoKitDC <> {0}", row["Items"]));
Posted
Updated 10-Jul-18 2:27am
v5
Comments
Kornfeld Eliyahu Peter 10-Jul-18 8:15am    
What do you mean 'not works'?
Any error?

I googled "datatable select not equal" and this was the first result

datatable - c# How do I specify a not in a select statement? - Stack Overflow[^]

Please do basic research such as searching before you ask a question.
 
Share this answer
 
That's because the filter uses "<>" not "!=" for "not equal to".
Try
string.Format("CodigoKitDC <> {0}", row["Items"]));
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 10-Jul-18 8:44am    
Actually T-SQL knows both != and <>...
The problem is with the .NET layer that knows only standard...
OriginalGriff 10-Jul-18 8:53am    
I know: did I mention SQL? :laugh:
Since the expression is in a string literal, you have to use SQL syntax, thus "<>" is the correct inequality operator.

Saying "but it not work" does not give us enough information to help you further. Put your code into a try/catch block so you can see the exception being generated (if any).

Go here for a complete list of valid operators for the Select method expression. You'll need to scroll about halfway down the page:

DataColumn.Expression Property (System.Data)[^]
 
Share this answer
 
v4
Comments
Kornfeld Eliyahu Peter 10-Jul-18 8:44am    
Actually T-SQL knows both != and <>...
The problem is with the .NET layer that knows only standard...
#realJSOP 10-Jul-18 9:02am    
.Net hasn't caught up with sql 2008 in this regard.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900