473,386 Members | 1,827 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,386 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 2191
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.