Using system;using system.collections.generic;using system.linq;using system.text;using System.IO;using System.data.sqlclient;using system.data;using system.drawing.imaging;using System.drawing;namespace get name {class program {static void Main (string[] args) {string path = @ "C:\Users\Chinaese\Desktop\_FabricI MG "; string x = Path.getfilename (Path.getdirectoryname (Path)); DirectoryInfo root = new DirectoryInfo (path); Directoryinfo[] Childdirs = root. GetDirectories (); Fileinfo[] files = root. GetFiles (); list<string> filename = new list<string> (); foreach (FileInfo item in files) {filename. ADD (Path.getfilenamewithoutextension (item. FullName)); } string [email protected] "Data Source = 192.168.0.180; Initial Catalog = PMS; User Id = sa; Password = hualong2012; "; using (SqlConnection connection = new SQLConnection (connectionString)) {SqlCommand command = new SqlCommand ("Select Flowercod E,picimg from Flowerpics where Flowerid in (SELECT MAX (Flowerid) as Expr1 from Flowerpics GROUP by flowercod e) ", connection); Connection. Open (); SqlDataReader reader = command. ExecuteReader (); Determines whether the data is read to the tail. while (reader. Read ()) {//Declaration array, used to hold the database's binary data byte[] MyByte = null; The read data is saved to the array in the try {if (filename. Contains (Reader[0])) {continue; } MyByte = (byte[]) reader["picimg"]; Image Image; Reads the array data into a file stream MemoryStream Mymemorystream = new MemoryStream (MyByte); Convert to a picture format. Image = Image.fromstream (Mymemorystream,true); Image. Save (Mymemorystream, imageformat.jpeg); Image. Save (@ "C:\Users\Chinaese\Desktop\SAMP\" + reader[0]. ToString () + ". bmp", SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.BMP); Mymemorystream. Close (); Closes the stream filename. ADD (Reader[0]. ToString ()); } catch (Exception) {//break; } finally {}//console.writeline (String.Format ("{0}, {1}" , Reader[0], reader[1]); }//Be sure to close the reader object. Reader. Close (); } console.readkey (); } }}
Export a picture from the Image Type field in SQL