How to write a CommandText to include db values

  • Thread starter Thread starter Chief
  • Start date Start date
C

Chief

Hi, i am baffled with this simple problem.

I want to try and pull out some info from a datatable,
using a sql query. i don't want to use a stored
procedure. How do i phrase my commandtext? i've messed
around with "+" symbols and extra apostrophes with no
success.

see my code:

private string test(SqlConnection conn)
{

string t = "";

SqlCommand cmd = new SqlCommand("SELECT Id FROM MyTable
WHERE Description = 'ugly'", conn);

cmd.ExecuteNonQuery();
return t;

}

thank you in advance,

Chief
 
Hi Chief
I see you already added the command text in the initialization
SqlCommand cmd = new SqlCommand("SELECT Id FROM MyTable
WHERE Description = 'ugly'", conn);
So, what is the problem with that, would you elaborate more.
thx
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC
 
Hi Chief,
from your sql, SELECT Id FROM MyTable WHERE Description = 'ugly' , will
return a value only if the 'ugly' exact mutch is exists in your DB, but
otherwise your phrase is correct. So i don't understant the prob, can you
clarify a bit more? you whant the ('ugly') part to add it to the string
dinamicaly?
 
Back
Top