By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

Invalid parameter used error

P: n/a

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


'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)

'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)


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


'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
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 =
End If

'Tidy Up


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

Dim image As System.Drawing.Image =

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


Dec 12 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.