rob
rob

Reputation: 227

Oraclebinary: Read data in C# .NET

I'm trying to read some binary data from Oracle using the System.Data.OracleClient namespace in C# .NET.

How do I convert the data from the OracleBinary class value to an integer?

            OracleConnection conn = new OracleConnection("Data Source=database;User Id=me;Password=me;");
            OracleCommand cmd = new OracleCommand("Select * From SomeData.TableName WHERE vid = 4527", conn);
            conn.Open();

            OracleDataReader reader = cmd.ExecuteReader();
            try
            {
                while (reader.Read())
                {
                    OracleBinary obj = reader.GetOracleBinary(5);
                    // here....
                }
            }
            finally 
            {
                reader.Close();
            }

            cmd.Dispose();

            conn.Close();
            conn.Dispose();

In the documentation for this database the columns definition reads that the data type is LONG RAW and "The values stored in Binary Large OBject (BLOB) format."

I was expecting some integers (negative & positive) from the BLOB.

not sure if anyone can help as I'm not able to ask the administrator no longer (moved on). If anyone could point me in a direction I would much appreciated.

EDIT: Just to expand (I missed a bit of info) on what the blob contains:

A vector of position log values such that the first element is the first measured depth value, the second element is the first true vertical depth value, the third element is the first x offset, the fourth is the first y offset, the fifth is the second measred depth

Many Thanks Rob

Upvotes: 1

Views: 2793

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292695

How do I convert the data from the OracleBinary class value to an integer?

Here it is:

OracleBinary obj = reader.GetOracleBinary(5);
byte[] bytes = obj.Value;
int value = BitConverter.ToInt32(bytes);

But are you sure that's what you really want? Integer values are usually not stored in BLOBs... BLOBs are designed to contain arbitrary binary data, such as an image.

Upvotes: 1

Related Questions