473,408 Members | 2,734 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,408 software developers and data experts.

Access 97 Images

Bob
I'm looking for an example of how to extract images from an Access 97 blob into an asp datagrid. Anybody have examples?
Nov 20 '05 #1
8 3584
Here's some code extracted from appdev courseware (www.appdev.com)
that was written by Andy Baron, Ken Getz and myself. When you're
working with blobs that originated in Access, you have to strip off
the header info that Access uses for OLE fields. This sample was
designed for a windows form and works with SQLS Northwind, but the
concept is the same -- you have to stream in the data and strip off
those header bytes before you can use the image for anything. I can
probably dig up the VB code from somewhere if you can't figure out the
C#.

--mary

private void LoadEmployeePhoto(int employeeID)
{
SqlDataAdapter da = null;
DataTable dt = new DataTable();
string strCnn =
"Data Source=(local);Database=Northwind;"
+ "Integrated Security=SSPI";
string strSQL =
"SELECT Photo FROM dbo.Employees"
+ " WHERE EmployeeID = "
+ employeeID.ToString();
MemoryStream msPic;
// Signature bytes of an
// OLE container header.
const byte OLEbyte0 = 21;
const byte OLEbyte1 = 28;
// Number of bytes in
// an OLE container header.
const int OLEheaderLength = 78;

da = new SqlDataAdapter(strSQL, strCnn);
da.Fill(dt);
if (dt.Rows.Count == 0)
return;

// Move binary picture data into the byte array
byte[] abytPic = (byte[])dt.Rows[0]["Photo"];

// Test for an OLE container header
if ((abytPic[0] == OLEbyte0)
&& (abytPic[1] == OLEbyte1))
{
// Use a second array to strip off the header.
// Make it big enough to hold
// the bytes after the header.
byte[] abytStripped =
new byte[abytPic.Length - OLEheaderLength];
// Strip off the header by copying the bytes
// after the header.
System.Buffer.BlockCopy(
abytPic, OLEheaderLength, abytStripped,
0, abytPic.Length - OLEheaderLength);

// Load the new byte array
// into a MemoryStream.
msPic = new MemoryStream(abytStripped);
}
else
{
// Load the original byte array into a MemoryStream
msPic = new MemoryStream(abytPic);
}
// Set the picture box image, using the stream.
picEmployee.Image = Image.FromStream(msPic);
}
On Wed, 14 Apr 2004 14:16:06 -0700, Bob <Az*****@cox.net> wrote:
I'm looking for an example of how to extract images from an Access 97 blob into an asp datagrid. Anybody have examples?


Nov 20 '05 #2

Mary,

Thanx for your answer. I tried your suggestions and of course can get it
to work with SQL Northwind, but not Access Northwind. I do not believe
images are stored the same in each database. IN SQL "Photo" is an int16,
and there is a column labled PhotoPath which is an nvarchar 255. In
Access there is only a "Photo" column which is an OLE object.
Do you happen to know where I can find the format of the Access OLE
object described?
Again, thank you for taking time to answer my question.
Bob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
Hi Bob,

Are you sure it is in Access97 a blob field and not just a path on disk?

Cor
Nov 20 '05 #4
Let me get back to you on this -- I don't think we ever tested it
against Access directly, so it would be nice to know if the header
fields were of a different size (or whatever). It's basically just
streaming in a bunch of bytes, so the actual storage might be slightly
different between Jet and SQLS.

--mary

On Fri, 16 Apr 2004 13:30:24 -0700, Bob Heath <ro***********@cox.net>
wrote:

Mary,

Thanx for your answer. I tried your suggestions and of course can get it
to work with SQL Northwind, but not Access Northwind. I do not believe
images are stored the same in each database. IN SQL "Photo" is an int16,
and there is a column labled PhotoPath which is an nvarchar 255. In
Access there is only a "Photo" column which is an OLE object.
Do you happen to know where I can find the format of the Access OLE
object described?
Again, thank you for taking time to answer my question.
Bob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 20 '05 #5
Hi Bob,

Sorry,

Now I see I misreaded it.

I was very happy with that sample from Mary. I made from it in VBnet a
generic blob conversion, sample. And I was happy I had now at last a sample
which could do both (that 21 and 28 does that). However now there seems to
be a thirth format, so I am also curious for that. (Not more than curious).

I made it also workable as a background for an asp datagrid. However what do
you mean with pictures in an asp.datagrid?

Cor
Nov 20 '05 #6
On Fri, 16 Apr 2004 13:30:24 -0700, Bob Heath <ro***********@cox.net> wrote:

¤
¤ Mary,
¤
¤ Thanx for your answer. I tried your suggestions and of course can get it
¤ to work with SQL Northwind, but not Access Northwind. I do not believe
¤ images are stored the same in each database. IN SQL "Photo" is an int16,
¤ and there is a column labled PhotoPath which is an nvarchar 255. In
¤ Access there is only a "Photo" column which is an OLE object.
¤ Do you happen to know where I can find the format of the Access OLE
¤ object described?
¤ Again, thank you for taking time to answer my question.

There are several factors here that will affect your ability to retrieve this data. First, if it was
stored in an OLE object field, how was it stored? It could have been stored with a databound OLE
control via the native application for the file, or, it could have been stored as *chunks* or a
*stream* of binary bytes. The latter method is the best case scenario.

If it was stored using the OLE control, then the OLE header information (that will need to be
removed) will vary depending upon the file type and application used to store it. This is the worst
case scenario.

Maybe you identify which method was used.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #7

Paul,

The Access97 Images are from an OLE bound control that I paste gif
images into. Can you point me to when I can figure out how to extract
the gif file?
Thank you for your help.

Bob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8
On Mon, 19 Apr 2004 14:58:50 -0700, Bob Heath <ro***********@cox.net> wrote:

¤
¤ Paul,
¤
¤ The Access97 Images are from an OLE bound control that I paste gif
¤ images into. Can you point me to when I can figure out how to extract
¤ the gif file?
¤ Thank you for your help.

I will have to take a look at this. If it's a GIF file then it was probably stored with OLE headers
for Microsoft Photo Editor. If you could take a peek at the contents of the buffer using the code
Mary provided and look for "MSPhotoEd.3" this would confirm whether Photo Editor was used.

If Photo Editor wasn't used, we would probably need to see first 50 characters or so of the buffer.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #9

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

Similar topics

4
by: RichG | last post by:
I have an Access database/forms application that has images stored in it. I need to develop a new VB that utilizes Oracle or the file system as the underlying storage for these images. In order...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
4
by: bborden | last post by:
I am considering writing a database program that contains text and images with an easy to use interface for my friend's dermatology physician practice. Basically Patient information that links to...
3
by: Bob Dydd | last post by:
Hi Everybody I have an Access 2000 db with a setup for inserting images in records. I am using the image path only with the actual images stored elswhere on the hard disc. This works perfectly...
3
by: Alan | last post by:
Hi, I'm converting a database application from Access 97 to C#/SQL Server. Old database contains some images in OLE fields. I've figured out that there's OLE header preceeding actual image data...
1
by: gm | last post by:
Hi; I have written a database that tracks all the installation we have ever done. I have a small heating company. I have recently started keeping a directory of digital photographs of the...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
3
by: anthony | last post by:
I am going to have to start holding jpg files (about 6,000 - 10,000 a year) in our school database. Mainly, they will end up being printed as part of the children's profiles ie via a report. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.