3

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...

Neil Knight
  • 47,437
  • 25
  • 129
  • 188
aharon
  • 7,393
  • 10
  • 38
  • 49

3 Answers3

6

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)));
Aaron
  • 7,431
  • 12
  • 35
  • 37
3

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

David M
  • 71,481
  • 13
  • 158
  • 186
0

or in Linq

dc.Body.where(a+> a.body.contains("InputText")).Select(a=>a.body).ToList();
RoughPlace
  • 1,111
  • 1
  • 13
  • 23