Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
How to i check particular datacolumn contains given value with out looping, datacolumn from a datatable,
Posted

Use DataTable's Select(String expression) method. This method returns an array of DataRows (DataRow[]). So all you have to do is to check if the Length property of said returned array is greater than zero and your done.

Here is the MSDN reference: http://msdn.microsoft.com/en-us/library/det4aw50%28v=VS.90%29.aspx[^].

Best Regards,

—MRB
 
Share this answer
 
You really can't... You can write LINQ code that effects a where clause to filter it, but even if YOU aren't looping IT is. Loops are a basic, nearly inescapable prospect in programming. If you're looking for magic, I'm afraid you'll have to keep looking.

var rowsWithTheValue = myTable.Rows.Where(a => a["Column"] == value);
 
Share this answer
 
Comments
Manfred Rudolf Bihy 14-Sep-11 10:02am    
I think this is what OP was after: Trying to avoid to explicitely loop through the data table. 5+

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