C# - 如何获取 oracle long 原始类型值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2644572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:25:50  来源:igfitidea点击:

C# - How to get oracle long raw type value

c#oracle

提问by Chicharito

How to get long raw type value with C#?

如何使用 C# 获取 long 原始类型值?

回答by Igby Largeman

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.

由于你还没有发布任何代码,我不知道你知道多少。我将假设您已经了解如何使用 OracleDataReader 执行查询并取回结果集。

There is one gotcha with LONG and LONG RAW columns. You must set the InitialLONGFetchSizeproperty of your OracleCommandto a non-zero value.

LONG 和 LONG RAW 列有一个问题。您必须将您的InitialLONGFetchSize属性设置为OracleCommand非零值。

The default value of InitialLONGFetchSizeis 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.

的默认值InitialLONGFetchSize为零,这意味着不会检索 LONG 或 LONG RAW 列的数据。如果将其设置为 -1,则将检索所有数据。对于较大的值,您可能不想这样做。如果您将其设置为大于零的任何值,这就是最初获取和缓存的字节数。

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

你应该阅读的文档InitialLONGFetchSize,因为有你需要知道的一些其他细节。

回答by Mouzam Basheer

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;
            }




        }