First, store the picture in the Oracle Database Demonstration Table News Structure: NewsID Number (10), Title Varchar2 (100), Image (BLOB) Method 1: Using OracleCommandBuilder classes (this class is used to automatically generate changes for coordination DataSet) Single meter command with associated database.
DIM CN AS New OracleConnection ("Data Source = Site; UID = GF; PWD = Macro;") CN.Open () DA AS NEW ORACLEDATAADAPTER ("Select * from news", cn) DIM Mycb AS New OracleCommandBuilder (DA ) Dim ds as New DataSet ( "news") da.MissingSchemaAction = MissingSchemaAction.AddWithKey Dim fs as Stream = File1.PostedFile.InputStream 'File1 file selection box, use Dim mydata (fs.Length) as Byte fs as a server control. Read (MyData, 0, fs.length) fs.close () Da.Close () DA. Fill (DS, "News") DIM MyRow As DataRow = DS.TABLES ("news"). Newrow Myrow ("newsid") = txtnewsid.text Myrow ("Title") = txttitle.text myrow ("image") = mydata ds.tables ("news"). Rows.add (Myrow) DA.UPDATE (DS, "News") cn.close () method 2 : Using the process prior defined Oracle process to: Create or Replace Procedure "GF". "News_add" (IN_NEWSID IN News.NEWSID% TYPE, IN_TITLE IN News.TILE% TYPE, IN_IMAG in News.Image% TYPE) AS Begin Insert Into GF.NEWS VALUES (IN_NEWSID, IN_TILE, IN_IMAG e); end; the following is the code to store data into the database: DIM CN AS New OracleConnection ("Data Source = Site; UID = GF; PWD = Macro;") cn.open () DIM CMD AS New OracleCommand ("News_Add ", cn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add (New OracleParameter (" in_newsid ", OracleType.Number, 10)) cmd.Parameters (" in_newsid "). Value = txtNewsID.Text.Trim cmd.Parameters .Add ("in_title", oracletype.varchar, 100)) cmd.parameters ("in_title"). Value =
TXTTITLE.TEXT.TRIM DIM FS AS STREAM = file1.postedfile.inputStream Dim MyData (fs.length) AS BYTE 'Defines a byte array for reading the image stream fs.read (MyData, 0, fs.length) fs. CLOSE () cmd.Parameters.Add ("in_image", oracletype.blob) cmd.parameters ("in_image"). Value = mydata cmd.executenonury () cn.close () Second, read from Oracle Database Picture method 1: Read data from the database and retain it on the server on the server DIM CONN AS New OracleEnt.OracleConnection Dim Cmd AS New OracleClient.OrClexMMand Dim MyReader AS OracleClient.OracleDataReader Dim SQL AS STRING DIM FL AS File SQL = " Select * from news where news = 3211 "Remove the picture data from the database blob conn.connectionstring =" password = macro; user ID = gf; data source = site "cmd.commandtext = SQL cmd.connection = conn conn.open ) MyReader = cmd.executeReader (Commandbehavior.SequentialAraccess) MyReader.Read () label1.text = MyReader ("Title" 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 flyd by getBytes. DIM RETVAL AS long' The bytes returned from getBytes. Dim StartIndex as long = 0 'the start position in the blob output. Dim fpath as string' stores the image data File FPath = Server.mappath (Request.ApplicationPath) & "
/Image/photo.bmp "fs = New FileStream (fpath, 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 (2, startIdex, outbyte, 0, buffersize) 'getBytes Returns the number of bytes in the field, the first parameter is the column number' Continue Reading and Writing While there is bytes beyond the size of the buffer. do while (outbyte) bw.flush () 'Clean all buffers of the current writer to write all buffer data to the infrastructure.' reposition the start index to the end of the last buffer and fill the buffer. startIndex = startIndex bufferSize retval = myReader.GetBytes (2, 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 A Nd the connection. MyReader.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.image.imageformat.jpeg) 'me.image1.width = new unit (300)' Adjustment display size 'me.image1.height = new unit (350) me.image1.imageURL = " Image / zkjhy.jpeg "Author Blog:
http://blog.9cbs.net/gaofeng2000/