From: Rich P on
--pseudo code here with the Like keyword -- how to apply it?

var query1 = from DataRow myRow in ds1.Tables["tblA"].Rows
where (string)myRow["Company"] Like "test"
select myRow;


I found this sample on the net:

list = list.Where(o => SqlMethods.Like(o.FirstName, FirstName))

How could I apply something like this to the query above?

Rich

*** Sent via Developersdex http://www.developersdex.com ***
From: Rich P on
I forgot to include the wildcards:

var query1 = from DataRow myRow in ds1.Tables["tblA"].Rows
where (string)myRow["Company"] Like "%test%"
select myRow;

how to handle 'Like' and wildcards with linq?

note: this query works if it is a straight '=='

Thanks

Rich

*** Sent via Developersdex http://www.developersdex.com ***
From: Rich P on
I added a reference to System.Data.Linq

and a

using System.Data.Linq.SqlClient;

and attempted the following query:

var query1 = from DataRow myRow in ds1.Tables["tblA"].Rows
where SqlMethods.Like(myRow["Company"], "%test%")
select myRow;


In the error message that ensued -- it mentioned that SqlMethods
currently only works with Linq To Sql. I guess this is Linq to a
Datatable. The rest of the error said that I had some invalid argument
--

perhaps myRow["Company"] ?


Rich

*** Sent via Developersdex http://www.developersdex.com ***
From: Alberto Poblacion on
"Rich P" <rpng123(a)aol.com> wrote in message
news:%23py3aJQ$KHA.5044(a)TK2MSFTNGP04.phx.gbl...
> var query1 = from DataRow myRow in ds1.Tables["tblA"].Rows
> where (string)myRow["Company"] Like "%test%"
> select myRow;

You can express the preceding with the "Contains" method:

var query1 = from myRow in ds1.Tables["tblA"].AsEnumerable()
where myRow.Field<string>("Company").Contains("test")
select myRow:

If you only want the "%" at the end, you can use "StartsWith" instead of
"Contains".

From: Rich P on
Thanks. I will give that a try. Although, in my searching, other
articles suggested that Contains does not handle wildcards. I guess I
will find out.

Thanks again for the reply and suggestion.

Rich

*** Sent via Developersdex http://www.developersdex.com ***