Invalid parameter used error

J

jaffar

Hi

I am storing images in an access database, based on an MSDN article.
The code i use to store is as follows:

<code>

'Create the command object
Dim command As New OleDbCommand("ImageBlobUpdate", dataConnection)
Command.CommandType = CommandType.StoredProcedure)

'Get the byte array from the posted file
Dim stream As IO.Stream = sourceFile.ImputStream ' sourceFile is a
HttpPostedFile object
Dim bytes(Cint(stream.Length() - 1)) As Byte
stream.Read(bytes, 1, bytes.Length)
stream.Close

'Update the record
command.Parameters.Add("id", id)
Dim parameter As New OleDbParameter("[Image]"),
OleDbType.LongVarBinary, bytes.Length, ParameterDirection.Imput,
False, 0, 0, Nothing, DataRowVersion.Current, bytes)
command.Parameters.Add(parameter)
command.ExecuteNonQuery

</code>

This updates the database fine. I then use the following code to
extract it and convert it to the image:

<code>

'Get a reader containing the image data
Dim command As New OleDbCommand("ImageBlobSelect", dataConnection)
Command.CommandType = CommandType.StoredProcedure)
command.Parameters.Add("id", id)
Dim reader As OleDbDataReader = command.ExecuteReader

'Get the image from the reader
If reader.HasRows Then
reader.Read
Dim bytes(CInt(reader.GetBytes(0, 0, Nothing, 0, Integer.MaxValue)
- 1)) As Byte
reader.GetBytes(0, 0, bytes, 0, bytes.Length)
Dim stream As New IO.MemoryStream(bytes, 0, bytes.Length)
Dim image As System.Drawing.Image =
System.Drawing.Image.FromStream(stream)
End If

'Tidy Up
reader.Close

</code>

When running the code, the error 'Invalid parameter used' is occurs on
the line:

Dim image As System.Drawing.Image =
System.Drawing.Image.FromStream(stream)

If i simply write the stream to file, then the file that is created is
the same size as the original image, however it cannot be viewed in
any editor.

The original image is a .JPG.

Any ideas greatly appreciated, I have searched and most solutions
relate to the image header offset, but i do not think this is the
issue.

Cheers

jaffar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top