Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - How to get oracle long raw type value

Tags:

c#

oracle

How to get long raw type value with C#?

like image 642
Chicharito Avatar asked Apr 15 '10 10:04

Chicharito


2 Answers

Since you haven't posted any code, I don't know how much you know. I'm going to assume you already understand how to execute a query and get back a result set using OracleDataReader.

There is one gotcha with LONG and LONG RAW columns. You must set the InitialLONGFetchSize property of your OracleCommand to a non-zero value.

The default value of InitialLONGFetchSize is zero, which means no data will be retrieved for LONG or LONG RAW columns. If you set it to -1, all data will be retrieved . You might not want to do this for large values. If you set it to anything above zero, that's how many bytes will be intially fetched and cached.

You should read the documentation for InitialLONGFetchSize, because there are some other details you need to know.

like image 108
Igby Largeman Avatar answered Nov 05 '22 13:11

Igby Largeman


Here is Code to solve this issue.

          Byte[] img;
        con.Open();
        OracleCommand command = new OracleCommand("Select Image as BLOBDATA FROM tbltestImage ", con);
        command.InitialLONGFetchSize = -1;
        OracleDataReader rdr = command.ExecuteReader();

        DataTable dt = new DataTable();
        dt.Load(rdr);
        con.Close();
         if (dt.Rows.Count > 0)
        {

            if (dt.Rows[0]["BLOBDATA"].ToString() != "")
            {

                img = (Byte[])dt.Rows[0]["BLOBDATA"];


                MemoryStream ms = new MemoryStream(img);

                Bitmap bitmap = new Bitmap(ms);

                pictureBox2.Image = bitmap;

                pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
            }




        }
like image 24
Mouzam Basheer Avatar answered Nov 05 '22 13:11

Mouzam Basheer