OracleConnection con = new OracleConnection("Data Source=localhost;uid=test;pwd=test;"); con.Open(); try { OracleCommand cmd = new OracleCommand("Select Token_no,Photo from party_photo where token_no=8629", con); // Writes the BLOB to a file (*.bmp). FileStream stream; // Streams the BLOB to the FileStream object. BinaryWriter writer; // Size of the BLOB buffer. int bufferSize = 100; // The BLOB byte[] buffer to be filled by GetBytes. byte[] outByte = new byte[bufferSize]; // The bytes returned from GetBytes. long retval; // The starting position in the BLOB output. long startIndex = 0; // The publisher id to use in the file name. string token_no = ""; OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()) { //token_no = reader.GetString(0); token_no = Convert.ToString(reader[0]); stream = new FileStream("Photo" + token_no + ".bmp", FileMode.OpenOrCreate, FileAccess.Write); writer = new BinaryWriter(stream); startIndex = 0; retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize); while (retval == bufferSize) { writer.Write(outByte); writer.Flush(); startIndex += bufferSize; retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize); } writer.Write(outByte, 0, (int)retval - 1); writer.Flush(); //stream.Write(outByte, 0, (int)retval = 1); writer.Close(); pictureBox1.Image = Image.FromStream(stream); stream.Close(); } reader.Close(); } catch (Exception error) { MessageBox.Show(error.Message, "", MessageBoxButtons.OK); } finally { con.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)