Ive just started learning Linq. Ive just created a sample test like this.
Dim dt As New DataTable
Dim dc As New DataColumn
dc.ColumnName = "Test"
dt.Columns.Add(dc)
dt.Rows.Add("Test")
dt.Rows.Add("One test")
dt.Rows.Add("Second test")
Dim results = From myRow In dt.AsEnumerable
Where myRow("Test") = "Test"
Select myRow
For Each Row In results
Console.WriteLine(Row.Item(0).ToString())
Next
This returns the first row in the iteration.
But what if i want to use a LIKE operator using %? I cant get it to work.
Ive tried
Where myRow("Test") LIKE "Test%"
Sounds to me like you want to use StartsWith i.e.
Dim results = From myRow In dt.AsEnumerable
Where myRow("Test").StartsWith("Test")
Select myRow
Contains
will match anywhere in the string where as StartsWith
will only match if it's at the beginning of the string (same logic as Test%
).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments