c# - Insert browsed image using wpf -


i need insert image mysql using wpf. image can selected value of browse&choose button. don't have enough experience browse&choose image insertion. byte[] imagebytes = (byte[])predictedhelpneededarea; below code:

<button x:name="btnbrowse" content="browse" click="btnbrowse_click"/> <button x:name="btninsert" content="insert" click="btninsert_click"/> <image name="myimage"></image>

private void btninsert_click(object sender, routedeventargs e)     {         {                             if (myimage.source != null)             {                 mysqlconnection con = new mysqlconnection(constr);                 mysqlcommand cmd = new mysqlcommand("insert images (image_blob) values (@imagesource)", con);                 byte[] imagebytes = (byte[])predictedhelpneededarea;                 cmd.parameters.add("@imagesource", mysqldbtype.blob, imagebytes.length).value = imagebytes;                 con.open();                 int = cmd.executenonquery();                 if (i > 0)                 {                     messagebox.show("image inserted");                 }              }             else             {                 messagebox.show("choose image");             }         }      }      private void btnbrowse_click(object sender, routedeventargs e)     {         stream checkstream = null;         microsoft.win32.openfiledialog openfiledialog = new microsoft.win32.openfiledialog();         openfiledialog.multiselect = false;         openfiledialog.filter = "all image files | *.*";         if ((bool)openfiledialog.showdialog())         {             try             {                 if ((checkstream = openfiledialog.openfile()) != null)                 {                     myimage.source = new bitmapimage(new uri(openfiledialog.filename, urikind.absolute));                                            messagebox.show("successfully done");                 }             }             catch (exception ex)             {                 messagebox.show("error: not read file disk. original error: " + ex.message);             }          }         else         {              messagebox.show("problem occured, try again later");          }     } 


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -