Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 606077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:12:56+00:00 2026-05-13T17:12:56+00:00

I have simple database in Access .mdb file, but I don’t know how to

  • 0

I have simple database in Access .mdb file, but I don’t know how to deal with: “parameter not valid” exception when Im creating Image from stream.
I’v read that I need to strip 78 bytes offset (from here) but I still get a “parameter not valid” error
when I call FromStream, even after stripping off the first 78 bytes.


This doesn’t work for me:

byte[] abytPic = (byte[])dt.Rows[0]["Photo"]; byte arrary with image
if ((abytPic[0] == 21) && (abytPic[1] == 28)) //It's true
{
    byte[] abytStripped = new byte[abytPic.Length - 78];
    System.Buffer.BlockCopy(abytPic, 78, abytStripped, 0, abytPic.Length - 78); 
    msPic = new emoryStream(abytStripped);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:12:57+00:00Added an answer on May 13, 2026 at 5:12 pm

    If you are reading the data directly from MS Access, you do not need to strip any header information.

    Assuming the image is stored as a BLOB, which is the most common, here is code to read in the array of bytes from the database and store as an image file (sorry, VB instead of C#):

      Dim varBytes() As Byte
    
      Using cn As New OleDbConnection(myConnectionString)
         cn.Open()
    
         sqlText = "SELECT [myColumn] " _
                  & "FROM [myTable] " _
                  & "WHERE ([mySearchCriteria] = '" & mySearchTerm & "')"
    
         Using cm As New OleDbCommand(sqlText, cn)
            Dim rdr As OleDbDataReader
    
            rdr = cm.ExecuteReader
    
            rdr.Read()
    
            varBytes = rdr.GetValue(0)
         End Using
    
      End Using
    
      My.Computer.FileSystem.WriteAllBytes(myPath & "\myFile.emf", varBytes, True)
    

    This example that I had laying around is one where I knew the files in the database were .emf images. If you know the extension, you can put it on the file name. If you don’t, you can leave it blank and then open the resulting with an image viewer; it should start. If you need to find the extension or file type, once it is saved as a file, you can open it with any hex editor and the file type will be available from the header information.

    Your question is a little bit unclear, so I’m not sure the above code is exactly what you want, but it should get you a lot closer.

    EDIT:

    This is the VB code that takes the array of bytes, loads it into a MemoryStream object, and then creates an Image object from the Stream. This bit of code worked just fine, and displayed the image in a picturebox on my form.

      Dim img As Image
      Dim str As New MemoryStream(varBytes)
      img = Image.FromStream(str)
      PictureBox1.Image = img
    

    If the C# equivalent of this is not working for you, then the problem is likely in how the image is stored in the MS Access database.

    EDIT:

    If the image in your database is stored as a ‘Package’ and not a ‘Long binary data’, then you will need to strip the header information that MS Access adds. I’ve been playing with the ‘Package’ type of image storage with a simple .jpg file. The header in this case is much longer than 78 bytes. In this instance, it’s actually 234 bytes, and MS Access also added some information to the end of the original file; about 292 bytes in this case.

    It looks like your original approach was correct, you will just need to determine how many bytes to strip off the front and rear of the Byte array for your situation.

    I determined it for my file by comparing the original image file, and the file exported from the database, (not to a Stream object, see my first code) in a hex editor. Once I figured out how much information (header and footer) was added by MS Access, I then knew how many bytes needed to be stripped.

    EDIT:

    The size of the header added by MS Access when the image is stored as ‘Package’ varies depending on the file type, and the original location (full path information) of the image when it was dumped into the MS Access database. So, even for the same file type, you may have a different number of bytes to strip from the header for each file.
    This makes it a lot more difficult, because then you will have to scan the byte array until you find the normal start-of-file information for that file type, and then strip everything before it.

    All this headache is one of the reasons that it is better to store images as BLOBs ‘Long binary data’ in a database. Retrieval is much easier. I don’t know if you have the option to do this, but if so, it would be a good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to connect to an Access 2000 database file (*.mdb), but I
I have a requirement to create a simple database in Access to collect some
I am writing a simple database with web access. I have previous experience with
I am implementing a very simple file database. I have 2 basic operations: void
I have a *.MDB database file, and I am wondering if it is possible
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have a simple database with two tables. Users and Configurations. A user has
I have two simple tables in my database. A card table that contains Id,
I have a simple app that uses an SQL Express 2005 database. When the
I have a simple problem when querying the SQL Server 2005 database. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.