c# - Getting error:Operand type clash: nvarchar is incompatible with image -
i have image field in tblemployee employee's picture.
when trying save employee's detail without image file in uploader threw , error
"operand type clash: nvarchar incompatible image"
while when select picture dialog box works fine. using c# windows applications.
my code looks as:
byte[] bimage=null; if(txtpic.text!="") { string image=txtpic.text; bitmap bmp=new bitmap(image); filestream fs=new filestream(image,filemode.open,fileaccess.read); bimage=new byte[fs.length]; fs.read(bimage,0,convert.toint32(fs.length)); fs.close(); } cmd = new sqlcommand("sp_insert_new_employee",conn); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.addwithvalue("@name",txtname.text.trim()); cmd.parameters.addwithvalue("@fname",txtfname.text.trim()); cmd.parameters.addwithvalue("@dob",convert.todatetime(dtdob.text)); cmd.parameters.addwithvalue("@nic",txtcnic.text.trim()); cmd.parameters.addwithvalue("@add",txtadd.text.trim()); cmd.parameters.addwithvalue("@emptype",cmbemptype.selecteditem.tostring()); if(bimage!=null) cmd.parameters.addwithvalue("@imgdata", sqldbtype.image).value = bimage; else cmd.parameters.addwithvalue("@imgdata", sqldbtype.image).value = dbnull.value; cmd.parameters.addwithvalue("@descr",txtdescr.text.trim()); conn.open(); cmd.executenonquery(); conn.close(); messagebox.show("successfully added....!");`
any 1 have idea making mistake?
usually error while passing dbnull.value value. can try following.
instead of
cmd.parameters.addwithvalue("@imgdata", sqldbtype.image).value = dbnull.value;
use following.
sqlparameter imageparameter = new sqlparameter("@imgdata", sqldbtype.image); imageparameter .value = dbnull.value; cmd.parameters.add(imageparameter );
Comments
Post a Comment