9.12. Reading and Writing Binary Data with Oracle
You need to read and write binary data from and to an Oracle database.
Use the techniques shown in the following example.
The sample code contains two event handlers:
Clears the controls on the form and builds a SQL statement to get the record for the specified ID from the Oracle table TBL0912. A connection is created and a
commandis built using the SQL statement and executed to build a
BLOBis retrieved from the
DataReaderand displayed in the
PictureBoxon the form. The
NCLOBvalues are retrieved from the
DataReaderand displayed in text boxes on the form.
Gets the ID from the
TextBoxon the form. A
BLOBis retrieved from a user-specified file and loaded into a
Bytearray. An Oracle
DataAdapteris created and a new table is created using the
FillSchema( )command. A
CommandBuilderis created from the
DataAdapter. A new row is created where the
BLOBvalue is set from the file specified by the user and the
NCLOBvalues are set from the text boxes on the form. The new row is added to the table and the data updated back to the source.
The C# code is shown in Example 9-15.
Example 9-15. File: ReadWriteBinaryDataFromOracleForm.cs
// Namespaces, variables, and constants using System; using System.Configuration; using System.Drawing; using System.Windows.Forms; using System.Text; using System.IO; using System.Data; using System.Data.OracleClient; private OpenFileDialog ...