sql - Select Statement with Variable not working C# -


i have done bunch of select statements addwithvalue's , add's 1 can't seem work. works fine when put number in instead of @ordernum. tried @ordernum , '@ordernum' when put '' nothing happens on button click when use @ordernum says can't find ordernum in table. value in sql table char bit data maybe has it? ideas?

end of select statement:

where poitem.ordno  = @ordernum 

add :

cmd.parameters.add(new oledbparameter("@ordernum", potextbox.text)); 

the entire select statement (the resulting big c# string concatenated smaller chunks):

"select      cast(poitem.itnbr char(15) ccsid 37) itemno,      cast(poitem.itdsc char(15) ccsid 37) itdsc,      cast(poitem.house char(15) ccsid 37) hou,      cast(poitem.refno char(15) ccsid 37) ref,      cast(poitem.staic char(15) ccsid 37) staic,     poitem.qtyor,     cast(poitem.unmsr char(15) ccsid 37) unmsr,     poitem.umcnv,     poitem.dkqty,     poitem.stkqt,     cast(poitem.jobno char(15) ccsid 37) job,     cast(poitem.dptno char(15) ccsid 37) dept,      cast(poitem.vclnb char(15) ccsid 37) vclnb,      cast(poitem.whslc char(15) ccsid 37) whsloc,     poitem.ucorq,      cast(poitem.blcod char(15) ccsid 37) blcod,      cast(pomast.vndnr char(15) ccsid 37) vendor,      cast(pomast.pstts char(15) ccsid 37) pstts,     cast(vennam.vname char(15) ccsid 37) vname,      cast(overrd.bname char(15) ccsid 37) bname  pomast  left outer join poitem on pomast.ordno = poitem.ordno left outer join overrd on pomast.ordno = overrd.ordno left outer join vennam on pomast.vndnr = vennam.vndnr  poitem.ordno = @ordernum" 

you said able put number instead of @ordernum, mean store integer order numbers in char bit data column type or can there order numbers like: po1234?

as others have suggested need convert line:

where poitem.ordno  = @ordernum 

to

where poitem.ordno = ? 

and set parameter if poitem.ordno column contains integers no alpha characters:

int ponum = 0;  if (!string.isnullorwhitespace(potextbox.text))     int32.tryparse(potextbox.text.trim(), out ponum);  cmd.parameters.addwithvalue("?", ponum); 

if poitem.ordno column contains alpha characters send string instead of int parameter:

string ponum = "";  if (!string.isnullorwhitespace(potextbox.text))     ponum = potextbox.text.trim();  cmd.parameters.addwithvalue("?", ponum); 

try out , let know if works.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -