c# - How to save picturebox image into mysql database without imagepath -
i wanted know if possible save images database without image path example default image assigned picture box. sample code used requires image location.
byte[] imagebt = null; filestream fstream = new filestream(this.txtimage.text, filemode.open, fileaccess.read); binaryreader br = new binaryreader(fstream); imagebt = br.readbytes((int)fstream.length); conn.open(); mysqlcommand command = new mysqlcommand("insert images(image)values(@img)", conn); command.parameters.add(new mysqlparameter("@img", imagebt)); reader = command.executereader(); messagebox.show("saved"); while (reader.read()) { }
you can use memorystream
save image picturebox byte array
image image = picturebox.image; memorystream memorystream = new memorystream(); image.save(memorystream, imageformat.png); byte[] imagebt = memorystream.toarray();
other parts same.
Comments
Post a Comment