aharon
aharon

Reputation: 7623

"Like" query in adapter c#

I have a data adapter that was created from my data set. i want to do this query:

Select Body WHERE Body Like '%@INPUTTEXT%'.

how can i do it? i want the "@INPUTTEXT" to be a parameter but because of the "' " it's a simple text...

Upvotes: 3

Views: 2068

Answers (3)

RoughPlace
RoughPlace

Reputation: 1121

or in Linq

dc.Body.where(a+> a.body.contains("InputText")).Select(a=>a.body).ToList();

Upvotes: 0

Aaron
Aaron

Reputation: 7541

I've done this before to do what you're asking:

string cmdText = "select * from table where column like @INPUTTEXT";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(cmdText,conn);
cmd.Parameters.Add(new SqlParameter("@INPUTTEXT", string.Format("%{0}%",INPUTTEXT)));

Upvotes: 6

David M
David M

Reputation: 72840

WHERE BODY Like '%' + @inputtext + '%'

Upvotes: 3

Related Questions