blob照片显示 oracle_如何从oracle blob数据中显示图像

Hii,

i am trying to display image from Blob datatype of oracle10g in .net windows application.

i am using filestream to get the image but the when i set the steam object for display image it show the error (Cannot access a closed file).

My code is below.OracleConnection con = new OracleConnection("Data Source=localhost;uid=test;pwd=test;");

con.Open();

try

{

OracleCommand cmd = new OracleCommand("Select Token_no,Photo from party_photo where token_no=8629", con);

// Writes the BLOB to a file (*.bmp).

FileStream stream;

// Streams the BLOB to the FileStream object.

BinaryWriter writer;

// Size of the BLOB buffer.

int bufferSize = 100;

// The BLOB byte[] buffer to be filled by GetBytes.

byte[] outByte = new byte[bufferSize];

// The bytes returned from GetBytes.

long retval;

// The starting position in the BLOB output.

long startIndex = 0;

// The publisher id to use in the file name.

string token_no = "";

OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

while (reader.Read())

{

//token_no = reader.GetString(0);

token_no = Convert.ToString(reader[0]);

stream = new FileStream("Photo" + token_no + ".bmp", FileMode.OpenOrCreate, FileAccess.Write);

writer = new BinaryWriter(stream);

startIndex = 0;

retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

while (retval == bufferSize)

{

writer.Write(outByte);

writer.Flush();

startIndex += bufferSize;

retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

}

writer.Write(outByte, 0, (int)retval - 1);

writer.Flush();

//stream.Write(outByte, 0, (int)retval = 1);

writer.Close();

pictureBox1.Image = Image.FromStream(stream);

stream.Close();

}

reader.Close();

}

catch (Exception error)

{

MessageBox.Show(error.Message, "", MessageBoxButtons.OK);

}

finally

{

con.Close();

}

Please help me to short out this problem.

Thanks

解决方案Switching to ODAC[^] is probably a good idea, as MS has deprecated their oracle ado.net driver.

You''ll also get access to functionality that is better suited for retreiving oracle blob types.

Best regards

Espen Harlinn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值