G
Guest
I have a simple Web Form application that needs to interact with an existing
MS Access database. In general, this is working well.
I've connected to the DB via ADO.NET (OleDB) and am able to read all
"normal" fields correctly (via DataReader).
The problem arises when I try to read an "OLE Object" typed field. The
field actually contains binary data (a JPEG image) but when I use GetBytes()
to populate the byte[], the data is munged.
It looks like it's been translated into a Unicode representation. The data
is exactly twice as long as it should be and most of the extra data consists
of zeros immediatley after the real byte value (i.e. little endian short).
This would be easy to work around except that some of the data is altered
more severly. For instance, the value 0x80 is converted to 0x20AC.
Obviously, I missing something regarding data translation; a flag specifying
binary or some such. Any ideas?
Thanks,
-Rob
private void test()
{
FileStream os = new FileStream(fn, FileMode.Create);
BinaryWriter wr = new BinaryWriter(os);
int size = 10*1024;
int offset = 0;
byte[] buffer = new byte[size];
long res = size;
long sum = 0;
while(true)
{
res = reader.GetBytes(photoord, offset, buffer, 0, size);
if(res == 0) break;
wr.Write(buffer, 0, (int) res);
offset += size;
}
wr.Close();
}
MS Access database. In general, this is working well.
I've connected to the DB via ADO.NET (OleDB) and am able to read all
"normal" fields correctly (via DataReader).
The problem arises when I try to read an "OLE Object" typed field. The
field actually contains binary data (a JPEG image) but when I use GetBytes()
to populate the byte[], the data is munged.
It looks like it's been translated into a Unicode representation. The data
is exactly twice as long as it should be and most of the extra data consists
of zeros immediatley after the real byte value (i.e. little endian short).
This would be easy to work around except that some of the data is altered
more severly. For instance, the value 0x80 is converted to 0x20AC.
Obviously, I missing something regarding data translation; a flag specifying
binary or some such. Any ideas?
Thanks,
-Rob
private void test()
{
FileStream os = new FileStream(fn, FileMode.Create);
BinaryWriter wr = new BinaryWriter(os);
int size = 10*1024;
int offset = 0;
byte[] buffer = new byte[size];
long res = size;
long sum = 0;
while(true)
{
res = reader.GetBytes(photoord, offset, buffer, 0, size);
if(res == 0) break;
wr.Write(buffer, 0, (int) res);
offset += size;
}
wr.Close();
}