Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 08, 2008 06:36 PM by Diamsorn
0 Points
7 Posts
Feb 08, 2008 03:31 PM|LINK
Hi Guys.
I am currenly creating a new web app using Microsoft Visual Web Developer 2008 and an programming in C#.
I have currently got scripts running with Linq To SQL and they work fine, but my question is Can you use the "Like" function of SQL with the C# code?
Thanks in advance!
Tristan
Contributor
2119 Points
384 Posts
Feb 08, 2008 04:08 PM|LINK
Give this a shot:
string mPattern = "Dave" var query = from p in people where SqlMethods.Like(p.Name, mPattern) select p;
Feb 08, 2008 06:07 PM|LINK
I have managed to fin the answer myself (finally!) [:D]
You can do as Diamsorn has suggested but to clear things up for other people if they have this same problem.
The below code makes use of the "StartsWith" function. basically the script looks for all the records that have a number that starts with "INV".
var query = from i in invoices where i.Number.StartsWith("INV") select i.Number;
The code below makes use of the "EndsWith" function. Basically this script looks for all the records that have a number that ends with "024".
var query = from i in invoices where i.Number.EndsWith("024") select i.Number;
The function that worked for me was the "StartsWith" as I was trying to retreive all the invoice numbers from our Great Plains DB.
Hope This Helps anyone out there. [:D]
Feb 08, 2008 06:36 PM|LINK
Nice work there Tristan.
trma97
0 Points
7 Posts
How Can I Use Like With Linq?
Feb 08, 2008 03:31 PM|LINK
Hi Guys.
I am currenly creating a new web app using Microsoft Visual Web Developer 2008 and an programming in C#.
I have currently got scripts running with Linq To SQL and they work fine, but my question is Can you use the "Like" function of SQL with the C# code?
Thanks in advance!
Tristan
Diamsorn
Contributor
2119 Points
384 Posts
Re: How Can I Use Like With Linq?
Feb 08, 2008 04:08 PM|LINK
Give this a shot:
string mPattern = "Dave" var query = from p in people where SqlMethods.Like(p.Name, mPattern) select p;My Blog
trma97
0 Points
7 Posts
Re: How Can I Use Like With Linq?
Feb 08, 2008 06:07 PM|LINK
I have managed to fin the answer myself (finally!) [:D]
You can do as Diamsorn has suggested but to clear things up for other people if they have this same problem.
The below code makes use of the "StartsWith" function. basically the script looks for all the records that have a number that starts with "INV".
var query = from i in invoices where i.Number.StartsWith("INV") select i.Number;Diamsorn
Contributor
2119 Points
384 Posts
Re: How Can I Use Like With Linq?
Feb 08, 2008 06:36 PM|LINK
Nice work there Tristan.
My Blog