473,625 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("S ELECT * FROM TBLMEDIA WHERE
[MediaType]='Mug shot'", _DBConn)
Dim Reader As OleDbDataReader = Command.Execute Reader()
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.Ge tValue(3), Byte())

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

My.Computer.Cli pboard.SetImage (picture)

'Get the image from the clipboard
If My.Computer.Cli pboard.Contains Image() Then
picture = My.Computer.Cli pboard.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.FromStrea m(stream)

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

I understood you want to get images from MS Access database, but the
application failed with the line "Image.FromStre am(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(pi ctureData,78, pictureData.Len gth - 78 )
picture = Image.FromStrea m(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.FromStre am(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(pi ctureData,78, pictureData.Len gth - 78 )
picture = Image.FromStrea m(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-******@microsof t.com. I'm waiting for your reply.
As we discussed before, you can get me at v-******@microsof t.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-******@microsof t.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
1269
by: authorking | last post by:
How can I create and access a microsoft access database?
1
3174
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
1906
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 buttons: First, Previous, Next and Last to navigate between the records in the database, I begin to see wrong figures for Tax Payable. I tried DAO. It was even worse. I created the database manually. I do not know how to create a database by code only.
5
1505
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
2146
by: 1064871 | last post by:
Hi How to insert Data in Microsoft Access database using VB.net regards adil
11
12025
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 wanted to ask another question, for my coursework. Can u set reminders in a microsoft access database, and if yes, how? Thanks saher!!
1
2086
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 application should only be able to work using the application frontend. I have read about various ways to implement security in access database at http://msdn.microsoft.com/en-us/library/aa139961(office.10).aspx. For example i password lock it , i...
1
1943
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 database to connect to: "Format of the initialization string does not conform to specification starting at index 0" My on line instructor suggested I reinstall the C# software, which I did to no avail. There is another student in my class that...
2
2389
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 entered on the query, but sometimes open and sometimes dont! It gives this error! "Microsoft Access Database Engine Couldnot Recognize the !!as a valid field name or expression" When deleting the parameter entry on Query, and then opens the MainForm...
0
8259
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8192
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8358
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7188
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.