473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

size problem with ole object data type (blob) and ado.net

Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.

The result is, of course, not an image. I've tryed to manipulate my
array of byte to strip every two bytes but the result is an visible
image but not the correct image (it's a scrambled image that appears).

Please help, I really need to do this exportation of picture in .net
with the access db.
Thanks a lot for people whom can help me.
Jul 21 '05 #1
6 2192
Hi Pierre,

"Pierre-Benoit" <qu******@hotmail.com> wrote in message
news:cc**************************@posting.google.c om...
Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
Byte[] byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

would be enough :).

byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.


Are you sure that the data inside database is correct?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Jul 21 '05 #2
Hi Pierre,

"Pierre-Benoit" <qu******@hotmail.com> wrote in message
news:cc**************************@posting.google.c om...
Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
Byte[] byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

would be enough :).

byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.


Are you sure that the data inside database is correct?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Jul 21 '05 #3
I know with some older image formats you must actually run ahead of some of
the old header input. For instance when using the Northwind database you
would have to edit your code below to this:

byte[] blob = (byte[]) (ds.Tables["employees"].Rows[0]["photo"]);
_stream.Write (blob, 78, blob.Length -78); // hack's out the old header info
_bitmap = new Bitmap (stream);

If you're certain that the images are there you should look into this as a
likely solution.

rgds,
Trent Millar
"Pierre-Benoit" <qu******@hotmail.com> wrote in message
news:cc**************************@posting.google.c om...
Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.

The result is, of course, not an image. I've tryed to manipulate my
array of byte to strip every two bytes but the result is an visible
image but not the correct image (it's a scrambled image that appears).

Please help, I really need to do this exportation of picture in .net
with the access db.
Thanks a lot for people whom can help me.

Jul 21 '05 #4
I know with some older image formats you must actually run ahead of some of
the old header input. For instance when using the Northwind database you
would have to edit your code below to this:

byte[] blob = (byte[]) (ds.Tables["employees"].Rows[0]["photo"]);
_stream.Write (blob, 78, blob.Length -78); // hack's out the old header info
_bitmap = new Bitmap (stream);

If you're certain that the images are there you should look into this as a
likely solution.

rgds,
Trent Millar
"Pierre-Benoit" <qu******@hotmail.com> wrote in message
news:cc**************************@posting.google.c om...
Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.

The result is, of course, not an image. I've tryed to manipulate my
array of byte to strip every two bytes but the result is an visible
image but not the correct image (it's a scrambled image that appears).

Please help, I really need to do this exportation of picture in .net
with the access db.
Thanks a lot for people whom can help me.

Jul 21 '05 #5
Hello,

This doesn't work. I've founded a similar example on the web and already
tryed. Nothing more. The problem is not really in the header of the data.
But more on how these data are retrived from db.

The value inside the field is correct. Because when I use a VBA function
(into an Access form) I get the image correctly on the disk.
But when use .Net I get a file wicth size is the exact double of the
original.

For example, here you'll find juste a little piece of the begining of the
original file (that work) and the one that has been generated from .net

Original:
FF D8 FF E0 00 10 4A 46 49 46 00 01 01
00 00 01

Generated file
FF 00 D8 00 FF 00 E0 00 00 00 10 00 4A
00 46 00

If a made a breakpoint directly after getting the value from the field with
ado.net and read the length of what i've retrived I get the orignial size *
2

I suppose that ADO.NET make something to bring me crazy :) So do I need to
change something I my connection string do tell ado to don't do anything
strange ?
string strConnectionString="Provider=Microsoft.Jet.OLEDB. 4.0;Data
Source=c:\test\photodb.mdb;User Id=admin;Password=;";
cnMDB = new OleDbConnection(strConnectionString);
OleDbCommand cmdPhoto = new OleDbCommand(strQuery,cnMDB);
cnMDB.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmdPhoto);
DataSet ds = new DataSet();
da.Fill(ds, "tblRefAlbum");

Just after this instruction, the field size in the memory is twice the size
of the original data in db.

Help I need somebody, Help......

"Trent Millar" <th****@hotmail.com> wrote in message
news:8IFjc.273614$Pk3.85830@pd7tw1no...
I know with some older image formats you must actually run ahead of some of the old header input. For instance when using the Northwind database you
would have to edit your code below to this:

byte[] blob = (byte[]) (ds.Tables["employees"].Rows[0]["photo"]);
_stream.Write (blob, 78, blob.Length -78); // hack's out the old header info _bitmap = new Bitmap (stream);

If you're certain that the images are there you should look into this as a
likely solution.

rgds,
Trent Millar
"Pierre-Benoit" <qu******@hotmail.com> wrote in message
news:cc**************************@posting.google.c om...
Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.

The result is, of course, not an image. I've tryed to manipulate my
array of byte to strip every two bytes but the result is an visible
image but not the correct image (it's a scrambled image that appears).

Please help, I really need to do this exportation of picture in .net
with the access db.
Thanks a lot for people whom can help me.


Jul 21 '05 #6
Hello,

This doesn't work. I've founded a similar example on the web and already
tryed. Nothing more. The problem is not really in the header of the data.
But more on how these data are retrived from db.

The value inside the field is correct. Because when I use a VBA function
(into an Access form) I get the image correctly on the disk.
But when use .Net I get a file wicth size is the exact double of the
original.

For example, here you'll find juste a little piece of the begining of the
original file (that work) and the one that has been generated from .net

Original:
FF D8 FF E0 00 10 4A 46 49 46 00 01 01
00 00 01

Generated file
FF 00 D8 00 FF 00 E0 00 00 00 10 00 4A
00 46 00

If a made a breakpoint directly after getting the value from the field with
ado.net and read the length of what i've retrived I get the orignial size *
2

I suppose that ADO.NET make something to bring me crazy :) So do I need to
change something I my connection string do tell ado to don't do anything
strange ?
string strConnectionString="Provider=Microsoft.Jet.OLEDB. 4.0;Data
Source=c:\test\photodb.mdb;User Id=admin;Password=;";
cnMDB = new OleDbConnection(strConnectionString);
OleDbCommand cmdPhoto = new OleDbCommand(strQuery,cnMDB);
cnMDB.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmdPhoto);
DataSet ds = new DataSet();
da.Fill(ds, "tblRefAlbum");

Just after this instruction, the field size in the memory is twice the size
of the original data in db.

Help I need somebody, Help......

"Trent Millar" <th****@hotmail.com> wrote in message
news:8IFjc.273614$Pk3.85830@pd7tw1no...
I know with some older image formats you must actually run ahead of some of the old header input. For instance when using the Northwind database you
would have to edit your code below to this:

byte[] blob = (byte[]) (ds.Tables["employees"].Rows[0]["photo"]);
_stream.Write (blob, 78, blob.Length -78); // hack's out the old header info _bitmap = new Bitmap (stream);

If you're certain that the images are there you should look into this as a
likely solution.

rgds,
Trent Millar
"Pierre-Benoit" <qu******@hotmail.com> wrote in message
news:cc**************************@posting.google.c om...
Hi there,

I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.

The problem is that when I do the following

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);

I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.

The result is, of course, not an image. I've tryed to manipulate my
array of byte to strip every two bytes but the result is an visible
image but not the correct image (it's a scrambled image that appears).

Please help, I really need to do this exportation of picture in .net
with the access db.
Thanks a lot for people whom can help me.


Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bj?rn Terje Svennes | last post by:
I'm using ODBC to interface a Microsoft SQL Server 2000. One of the operations involves placing files within BLOBs. I'm using the image data type for this purpose. Most of the time this works okey,...
2
by: Stanley Sinclair | last post by:
About to create a table which will "include" a BLOB. Am not sure how large to make the container and the tablespace. What I see says that BLOB is stored "separately." However, I don't know...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
3
by: Ray | last post by:
I am having my first experience using BLOB as a row in a table. I am using it to insert graphics for labels we print. I have no problem inserting into and select from the table. The graphic is...
1
by: gimme_this_gimme_that | last post by:
In DB2, is it possible to update a table having a BLOB using a statement such as "SELECT MY_BLOB_FIELD FROM MY_TABLE FOR UPDATE" Then getting the Blob and writing to the Blob's output stream ? ...
3
by: Pierre-Benoit | last post by:
Hi there, I've a strange problem with ado.net and an Access db. I need to create a little C# app that take the content of "ole object" field and then save it into a file. The problem is that...
4
by: Yaro | last post by:
Hi, I am looking for information how calculate size of table with BLOB field. After RUNSTATS command select fpages * tablespace pagesize - gives me only 16kB (table contain about 10M) I...
4
by: =?Utf-8?B?UHVjY2E=?= | last post by:
The function that I'm trying to call through DLLImport has a parameter that has a C code's vector's Itrator to a structure. I Have marshalled the structure in C# but how do I do the C type...
2
by: sjping | last post by:
This is what I did: >db2 alter table C1016781_T1 alter column itemContent set data type blob(2097152) and I got: DB21034E The command was processed as an SQL statement because it was not a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.