Take a picture from Oracle and display! If it is .NET2002, you need another way to operate specialized Oracle libraries --------------------------------- -------------------------------------------------- ------------------- Imports system.drawing
DIM CONN AS NEW ORACLIENT.OrCleConnection () DIM CMD AS New OracleClient.OrcleCommand () Dim MyReader As OracleClient.OracleDataReader Dim SQL AS STRING DIM FL AS File
SQL = "SELECT JT from SD_GTZP" Removes Image Data from the Database BLOB Conn.connectionstring = "Password = Jlsbgis; User ID = Jlsbgis; Data Source = SJ" cmd.commandtext = SQL cmd.connection = conn
Conn.open () MyReader = cmd.executeReader (Commandbehavior.SequentialAracse) MyReader.Read ()
.. Dim fs As FileStream '. Writes the BLOB to a file (* .bmp) Dim bw As BinaryWriter' Streams the binary data to the FileStream object Dim bufferSize As Integer = 1000 'The size of the BLOB buffer Dim outbyte (bufferSize - 1) AS BYTE 'The blob byte () Buffer to be filled by getBytes. Dim RetVal as long' The bytes returned from getBytes. Dim StartIndex as long = 0 'The Starting Position in The Blob Output. Dim Fpath As String
FPath = server.mappath (request.applicationPath) & "/image/photo.bmp" 'Create image data into local file fs = new filestream (fipath, filemode.openorcreate, fileaccess.write) BW = new binarywriter (fs)
'Reset the starting byte for a new blob. StartIndex = 0
'Read bytes into outbyte () and retain the number of bytes returned. Retval = myReader.GetBytes (0, startIndex, outbyte, 0, bufferSize)' Continue reading and writing while there are bytes beyond the size of the buffer. Do While retval = bufferSize bw.Write (outbyte) bw.Flush () 'Reposition the start index to the end of the last buffer and fill the buffer. startIndex = startIndex bufferSize retval = myReader.GetBytes (0, startIndex, outbyte, 0, bufferSize LOOP
'Write the remaining buffer. Bw.write (outbyte) bw.flush ()' close the output file. Bw.close () fs.close ()
'Close the reader and the connection. MyReader.close () Conn.close () CONN.CLOSE ()
Dim logo As Image 'file format conversion logo = Image.FromFile (fpath) fpath = Server.MapPath (Request.ApplicationPath) & "/Image/zkjhy.jpeg" logo.Save (fpath, System.Drawing.Imaging.ImageFormat.Jpeg ) Logo.dispose () logo = Nothing me.Image1.width = new unit (300) 'Adjustment display size me.image1.Height = new unit (350) me.image1.imageURL = "image / zkjhy.jpeg" - -------------------------------------------------- -------------------------------------------------- ----------------------- // Store PRIVATE VOID Button1_Click (Object Sender, System.EventArgs E) {
OracleConnection con = new OracleConnection ( "Password = jlsbgis; User ID = jlsbgis; Data Source = sj"); OracleDataAdapter da = new OracleDataAdapter ( "Select * From MyImages", con); OracleCommandBuilder MyCB = new OracleCommandBuilder (da); DataSet ds = new DataSet ( "MyImages"); da.MissingSchemaAction = MissingSchemaAction.AddWithKey; FileStream fs = new FileStream (@ "d: /a.jpg", FileMode.OpenOrCreate, FileAccess.Read); byte [] MyData = new byte [ fs.length]; fs.read (MyData, 0, System.Convert.Toint32 (fs.length)); fs.close (); da.fill (DS, "MyImages"); DATAROW Myrow = DS.TABLES [" "]. Newrow (); myrow [" description "] =" this would be description text "; myrow [" imgfield "] = mydata; ds.tables [" myimages "]. Rows.add (MyRow); DA. Update (DS, "MyImages"); con.close ();