c# - How to display in a picturebox an byte array image from a sql table? -


this question has answer here:

i have image in sql table converted byte array.how can display in picture box when click on record datagridview contains table?i need actual code.thanks.this code have conversion:

private void button2_click(object sender, eventargs e) {     sqlconnection cn = new sqlconnection(@" data source=home-d2cadc8d4f\sql;initial catalog=motociclete;integrated security=true");     memorystream ms = new memorystream();     picturebox1.image.save(ms, system.drawing.imaging.imageformat.jpeg);      byte[] pic_arr = new byte[ms.length];     ms.position = 0;     ms.read(pic_arr, 0, pic_arr.length);      sqlcommand cmd = new sqlcommand("insert motociclete(firma,model,poza,pret,anf,greutate,caprez,putere,garantie,stoc) values (@firma,@model,@poza,@pret,@anf,@greutate,@caprez,@putere,@garantie,@stoc)",cn);     cmd.parameters.addwithvalue("@firma", textbox3.text);     cmd.parameters.addwithvalue("@model", textbox10.text);     cmd.parameters.addwithvalue("@poza", pic_arr);     cmd.parameters.addwithvalue("@pret", textbox7.text);     cmd.parameters.addwithvalue("@anf", textbox4.text);     cmd.parameters.addwithvalue("@greutate", textbox9.text);     cmd.parameters.addwithvalue("@caprez", textbox5.text);     cmd.parameters.addwithvalue("@putere", textbox8.text);     cmd.parameters.addwithvalue("@garantie", textbox6.text);     cmd.parameters.addwithvalue("@stoc", textbox2.text);      cn.open();      try     {         int rez = cmd.executenonquery();         if (rez > 0)         {             messagebox.show("adaugare reusita ");         }     }     catch (exception)     {         messagebox.show("inregistrarea exista deja ");     }         {         cn.close();         obj.loaddata();         this.close();     } } 

assuming picture byte[] fetched database:

byte[] picture = // read db picboximage.image = image.fromstream(new memorystream(picture));                                 picboximage.refresh(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -