Click here to Skip to main content
16,018,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dataset and I would like to know if there is a part of value in certain column exists.

What I have tried:

VB
Dim str as string = "Apple"
Dim contains As Boolean = ds.Tables("result").AsEnumerable().Any(Function(row) str= row.Field(Of [String])("COL1"))

This gives me true of false which is what I want.
but If my column has

Applea
AppleB

it should return true. Meaning it has to search for "Contains" instead of exact word.
Posted
Updated 4-Feb-16 9:25am
v2

So what's wrong with using the Contains method?
VB.NET
Dim str as string = "Apple"
Dim contains As Boolean = ds.Tables("result").AsEnumerable().Any(Function(row) row.Field(Of [String])("COL1").Contains(str))

Or, if you want a case-insensitive comparison:
VB.NET
Dim str as string = "Apple"
Dim contains As Boolean = ds.Tables("result").AsEnumerable().Any(Function(row) row.Field(Of [String])("COL1").IndexOf(str, StringComparison.OrdinalIgnoreCase) <> -1)
 
Share this answer
 
v3
Comments
Sascha Lefèvre 4-Feb-16 15:21pm    
+5
sudevsu 4-Feb-16 15:34pm    
I missed that simple thing. Thanks Richard. Just went out of space for few minutes.
There actually is a String-method "Contains(..)" :-)

String.Contains Method (String) (System)[^]

VB
Dim contains As Boolean = ds.Tables("result").AsEnumerable().Any(Function(row) row.Field(Of [String])("COL1").Contains(str))
 
Share this answer
 

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