Sri Ram

Sri Ram

  • 1.6k
  • 173
  • 99.7k

How to filter records from DataTable for a condition ">=" ?

Sep 26 2017 9:45 AM

I have a datatable with columns like First Name, Middle Name, Last Name. I need to filter the records in C# for a condition like shown below.

Select * From Table Where LastName >= 'john'

How to apply this where condition and get the filtered results set that will have records whose last names are like John, Justine, K*****, L***, M***.....Z*** ( last names from J to Z as per alphabetical order)
 
This datatable is populated by executing a stored procedure and I can't apply the filter at stored proc level as data is encrypted in backend.
 
I'm able to get the results for equality operator using the below logic.
e.g. 
SQL vesion:  Select * From Table Where LastName like '%john%'
  
C# version: 
var employees = ( from e in dtEmployee.AsEnumerable()
                       where e.Field<string>("LastName").Contains("john")
                       select e ).ToList();
 
Similarly, need to use the >= operator. How to get records for this filter condition? Can anyone please help on this?

Answers (7)