Read the picture to PictureBox, write the database SqlConnection conn = new sqlconnection (@ "data source = chenyuming2004 / vsdotnet; uid = sa; pwd = cym; database = lhf"); conn.open (); sqlcommand cmd = new SqlCommand ("INSERT INTO FUSER VALUES ('1A', '1B', @ i)", conn); byte [] ib = new byte [60000]; filestream fs = new filestream (@ "d: / windows temp / temp / 1.jpg ", filemode.open, flyaccess.read); fs.read (IB, 0, 60000); cmd.parameters.add (" @ i ", sqldbtype.image, (int) fs.length); cmd. Parameters ["@ i"]. Value = Ib; cmd.executenonquery (); conn.close ();
-------------------------------------------------- ----- Read the picture from the database to PictureBox
SqlConnection conn = new SqlConnection (@ "data source = chenyuming2004 / VSdotNET; uid = sa; pwd = cym; database = lhf"); conn.Open (); SqlCommand cmd = new SqlCommand ( "select pictures from fuser where password = ' 1b '", conn); sqldatareader reader = cmd.executeRead (); reader.read (); memorystream buf = new memorystream ((byte []) Reader [0]); image image = image.fromstream (buf, true) Picturebox1.image = image;