Formatting a variable for a WHERE statement

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

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top