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

Save Microsoft Access database OLE Objects (jpegs) to disk via VB.

I have an Access database with a table named 'tblMedia'. In tblMedia I have a
field named 'Media' that is defined as an 'OLE Ojbect' field. In this Media
field, I have pictures, they are jpegs. I'm using VB.NET 2005 and I would
like to open the Access database and write the OLE Objects to the file system.

Here's what I got and it's not working.

'Open connection to the Access database
OpenConnection()

Dim Command As New OleDbCommand("SELECT * FROM TBLMEDIA WHERE
[MediaType]='Mug shot'", _DBConn)
Dim Reader As OleDbDataReader = Command.ExecuteReader()
Dim picture As Image = Nothing

'Read each line of TBLMEDIA and write out to Media file
While Reader.Read
'Place image on the clipboard
Dim pictureData As Byte() = CType(Reader.GetValue(3), Byte())

Using stream As New IO.MemoryStream(pictureData)
picture = Image.FromStream(stream)
End Using

My.Computer.Clipboard.SetImage(picture)

'Get the image from the clipboard
If My.Computer.Clipboard.ContainsImage() Then
picture = My.Computer.Clipboard.GetImage

'Write the image to a disk file
picture.Save(Me.txtDestFolder.Text & "\" &
Reader.GetValue(1).ToString & ".jpg")
End If
End While
I get a 'Parameter is not valid.' error on this line above:
picture = Image.FromStream(stream)

--
Dave B.
Dec 11 '07 #1
4 5524
Hello Dave,

I understood you want to get images from MS Access database, but the
application failed with the line "Image.FromStream(stream)". The error
message is "Parameter is not valid". If I misunderstood anything here,
please correct me.

The array of bytes you received from OLE Ojbect filed contains a 78-byte
prefix that has nothing to do with the image. Those bytes are just the
header created when the image was added as an OLE object to MS Access. It
must undergo the following modification to work with the OLE field of MS
Access database:

Using stream As New IO.MemoryStream()
stream.Write(pictureData,78, pictureData.Length - 78 )
picture = Image.FromStream(stream)
End Using

Hope this helps. Please try this method and let me know the result. If you
face any further issue, feel free to update here again. We are glad to
assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 11 '07 #2
Wen,

I commented out my code and pasted yours in and I still get the same error
message "Parameter is not valid".

Any other suggestions?
--
Dave B.
"WenYuan Wang [MSFT]" wrote:
Hello Dave,

I understood you want to get images from MS Access database, but the
application failed with the line "Image.FromStream(stream)". The error
message is "Parameter is not valid". If I misunderstood anything here,
please correct me.

The array of bytes you received from OLE Ojbect filed contains a 78-byte
prefix that has nothing to do with the image. Those bytes are just the
header created when the image was added as an OLE object to MS Access. It
must undergo the following modification to work with the OLE field of MS
Access database:

Using stream As New IO.MemoryStream()
stream.Write(pictureData,78, pictureData.Length - 78 )
picture = Image.FromStream(stream)
End Using

Hope this helps. Please try this method and let me know the result. If you
face any further issue, feel free to update here again. We are glad to
assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 12 '07 #3
Hello Dave,
Thanks for your reply,

It seems you send the mail to a wrong address.
My alias is v-******@microsoft.com. I'm waiting for your reply.
As we discussed before, you can get me at v-******@microsoft.com.

I created an Access DB, and insert some jpeg images into it. Finally, I
reproduced it.
After research, I found 78 byte is used for BMP image. It doesn't work fine
with JPEG image file. Under my test, the offset for JPEG image is 189.but
I'm not sure. It seems the number dependens on the size of file.I need
perform further research.

Is it possible for you to give me your email Address? Thereby, I can pass
the information for you as soon as possible.(again, my alias is
v-******@microsoft.com. You can send an email to me.) If you have any more
concern, please also feel free to update here. We are glad to assist you.

Have a great day.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 14 '07 #4
WenYuan,

I have the same problem that is 'parameter not valid'. Do you have any
developments on the offset value for JPEG images? How do you determine if the
offset value is 189 or something else?

Cheers,
Marc
Mar 7 '08 #5

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

Similar topics

2
by: authorking | last post by:
How can I create and access a microsoft access database?
1
by: Michael Meckelein | last post by:
Hi, My csharp application access a MS Access database through odbc connection. Is there a way to compact the Access database after deleting records using the odbc connection?
0
by: Akinyemi | last post by:
I have developed a Tax Compution software based on Nigerian Tax System. The Software runs fine if I do not save the output into an Access Database throuth ADO. Once I begin to use navigation...
5
by: davepisarek | last post by:
I am looking for a quick and dirty way to create a hyperlink that will open a Microsoft access database written in asp.
1
by: 1064871 | last post by:
Hi How to insert Data in Microsoft Access database using VB.net regards adil
11
by: Saher | last post by:
Thanks, for the help! hey guys, thanks 4 the help. By the way my access still wont work, but its alright, because i dont need to use it immediately, and im getting a laptop, so it shud be fine. I...
1
by: titli | last post by:
Hi All, Please tell me the best solution to implemenet security in access databases , to save the tables, queries, forms , reports as well as the VBA code from user access. The users of the...
1
by: Drew Longo | last post by:
I am creating a form in visual C# 2008 and placed a data grid view control on it. I created a new connection, specified a microsoft access database, but get an error message after selecting the...
2
by: Mr Key | last post by:
Hi all, I have a parameter query running from myform named MainForm,(on AC2010) After a selection on the Combox from MainForm I wish I could always open the data according to parametersQuery...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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,...

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.