一断小代码,实现从数据库中获得图像
OleDbCommand cmd;
OleDbDataReader rdr;
int intBinaryBlobCol = 1;
int intOffset = 0;
int intBytesReturned;
int intChunkSize = 8192;
Byte[] aBinaryBlob = new byte[intChunkSize];
string strPathToFile = "getBytes.jpg";
FileStream fileOutput = new FileStream(strPathToFile, FileMode.Create);
rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
rdr.Read();
do
{
intBytesReturned = (int)rdr.GetBytes(intBinaryBlobCol,intOffset,aBinaryBlob,0,intChunkSize);
if(intBytesReturned > 0 )
{
fileOutput.Write(aBinaryBlob,0,intBytesReturned);
}
intOffset += intBytesReturned;
}while(intBytesReturned == intChunkSize);
fileOutput.Close();
rdr.Close();
OleDbDataReader rdr;
int intBinaryBlobCol = 1;
int intOffset = 0;
int intBytesReturned;
int intChunkSize = 8192;
Byte[] aBinaryBlob = new byte[intChunkSize];
string strPathToFile = "getBytes.jpg";
FileStream fileOutput = new FileStream(strPathToFile, FileMode.Create);
rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
rdr.Read();
do
{
intBytesReturned = (int)rdr.GetBytes(intBinaryBlobCol,intOffset,aBinaryBlob,0,intChunkSize);
if(intBytesReturned > 0 )
{
fileOutput.Write(aBinaryBlob,0,intBytesReturned);
}
intOffset += intBytesReturned;
}while(intBytesReturned == intChunkSize);
fileOutput.Close();
rdr.Close();