c# - Error in inserting the image to Mysql -


im using c# insert image mysql database. length of byte array 51115. however, when checked in database, length of field image (long blob) 13 bytes. wrong it? please me!

private void savebtn_click(object sender, eventargs e) {     try     {         image img = imgbox.image;         byte[] arr;         imageconverter converter = new imageconverter();         arr = (byte[])converter.convertto(img, typeof(byte[]));         messagebox.show(arr.length.tostring()); // 51115         string connectionstring = "server=localhost;user id=root;password=xrayadmin;database=xraydatabase";         string query = "insert imagedatabase(idpatient,image,diagnosisdoctor,diagnosisdate) values('" + convert.toint32(labpatid.text) + "','" +             arr + "','" + labdocuser.text + "','" + datetime.now.tostring("dd / mm / yyyy") + "')";         mysqlconnection mysqlconnection = new mysqlconnection(connectionstring);         mysqlcommand mysqlcmd = new mysqlcommand(query, mysqlconnection);         mysqldatareader datareader;         mysqlconnection.open();         datareader = mysqlcmd.executereader();         messagebox.show("save data");         while (datareader.read())         {          }         mysqlconnection.close();     }     catch (exception ex)     {         messagebox.show(ex.tostring());     }  } 

i recomend use parameters. this

string query = @"insert imagedatabase(idpatient,image,diagnosisdoctor,diagnosisdate) values(@idpatient,@image,@diagnosisdoctor,@diagnosisdate)" mysqlcmd.parameters.addwithvalue("@image", arr); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -