Read the picture to PictureBox, write to 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, FileAccess .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;