Formatting a variable for a WHERE statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a variable string "myvar" and I need to pass it to the WHERE clause of
a SELCET statement I have tried myvar.ToString(), Cint, parse and convert.

The Select statement works fine when I pass a value manually eg WHERE mycust
= "50".

Any ideas?

Thanks, Justin.
 
Justin,

What is the type of mycust column? If it is integer, the where clause should
look like
where mycust = 50
and it can be made by expression
String.Format ("where mycust ={0}", myvar);
If it is string, and your database accept single quote string delimiter like
where mycust = '50'
it can be made by expression
String.Format ("where mycust ='{0}'", myvar);
If double quote delimiter has to be used, use
String.Format ("where mycust =\"{0}\"", myvar);

Eliyahu
 
Back
Top