请问如何在asp.net+C# 下读取Oracle的CLob字段

急,请问有谁知道?
2025-03-04 01:10:48
推荐回答(1个)
回答1:

OracleConnection objOcon=new OracleConnection("user id=system;data source=user;password=pass");
OracleCommand objOcmd = new OracleCommand("select sopinstanceuid,dicomimage from images where

getdate is not null", objOcon);
FileStream fs;
BinaryWriter bw;

int bufferSize = 30; //方
byte[] outbyte = new byte[bufferSize];
long retval;
long startIndex = 0;

string pub_id = "";

pubsConn.Open();
OracleDataReader myReader = logoCMD.ExecuteReader(CommandBehavior.SequentialAccess);
while (myReader.Read())
{
pub_id = myReader.GetString(0);

fs = new FileStream("c:\\dicomimage\\" +pub_id + ".dcm", FileMode.OpenOrCreate,

FileAccess.Write);
bw = new BinaryWriter(fs);

startIndex = 0;

retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);

while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();

startIndex += bufferSize;
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);

}
if (retval>0)
{
bw.Write(outbyte, 0, (int)retval - 1);
}
bw.Flush();

bw.Close();
fs.Close();
}

myReader.Close();
pubsConn.Close();