473,498 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error " Invalid Parameter Used" when I try to display an image

I am trying to display images from an Access 2000 database and I get an error
"Invalid Parameter Used" when I execute the code line
"picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual Basic .Net
application.

I have researched MSDN for help and found the example article 321900 (see
below) and set up a test and everything works fine when I use SQL Server 2000
but when I modify the code and use data from Access 2000 using an
"OleDbDataAdapter" I get the error.

I tried a work around by importing my Access 2000 database into a SQL Server
data file and I get the same error using the sample code. If I load a picture
(jpg) into a SQL Server file and use the code sample it work but if I load
the same picture file into an Access 2000 file the code sample dosen't work.

What am I missing? Is There a parameter that I need when I use Access 2000?
How To Display an Image from a Database in a Windows Forms PictureBox by
Using Visual Basic .NET
Article ID : 321900 Last Review : July 15, 2004 Revision : 1.0
7. Add the following code in the Click event procedure of Button2:
Dim cn As New SqlConnection(strCn)
Dim cmd As New SqlCommand("SELECT BLOBID, " & _
"BLOBData FROM BLOBTest ORDER BY BLOBID", cn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "BLOBTest")
Dim c As Integer = ds.Tables("BLOBTest").Rows.Count
If c > 0 Then
Dim bytBLOBData() As Byte = _
ds.Tables("BLOBTest").Rows(c - 1)("BLOBData")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)
End If

Nov 22 '05 #1
10 7531
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are trying to get a picture from
Access 2000 database according to a KB article. If there is any
misunderstanding, please feel free to let me know.

Now let's focus on getting data from Access 2000 instead of importing data
in SQL Server. First of all, please change al the Sql object to OleDb
object in the System.Data.OleDb namespace to support Access. Then try to
run that code again. The code seems to be fine, I think there might be some
mismatch with the database tables. Could you let me know on which line did
the app stop and throws the exception?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #2
Sorry the code that I included with my first post was the example that I
followed when I tested the SQL data. Here is the code that I'm using when I
try to display an image from Access 2000.

Dim iRowCount As Integer = 0
Dim c As Integer = 0

bmbRptData = Me.BindingContext(DsMyTest1, "MyTestData")
DsMyTest1.Clear()

iRowCount = OleDbDataAdapter1.Fill(DsMyTest1)

curRow = DsMyTest1.Tables("MyTestData").Rows(bmbRptData.Pos ition)
c = bmbRptData.Position

curRow.BeginEdit()

MyPermit_No = curRow("Permit_No")

If c >= 0 Then
Try

Dim bytBLOBData() As Byte = _

DsMyTest1.Tables("MyTestData").Rows(c)("Sign_Photo ")

Dim stmBLOBData As New MemoryStream(bytBLOBData)

' The code jumps to the exception catch with the
' ex3.message = "Invalid Parameter Used"
' when I run the next line

picBlobMyTest.Image = Image.FromStream(stmBLOBData)

Catch ex1 As ArgumentOutOfRangeException
MessageBox.Show(ex1.Message, "Argument error")
Catch ex2 As UnauthorizedAccessException
MessageBox.Show(ex2.Message, "UnauthorizedAccess error")
Catch ex3 As Exception
MessageBox.Show(ex3.Message, "An unhandled exception error")

Finally


"Wally" wrote:
I am trying to display images from an Access 2000 database and I get an error
"Invalid Parameter Used" when I execute the code line
"picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual Basic .Net
application.

I have researched MSDN for help and found the example article 321900 (see
below) and set up a test and everything works fine when I use SQL Server 2000
but when I modify the code and use data from Access 2000 using an
"OleDbDataAdapter" I get the error.

I tried a work around by importing my Access 2000 database into a SQL Server
data file and I get the same error using the sample code. If I load a picture
(jpg) into a SQL Server file and use the code sample it work but if I load
the same picture file into an Access 2000 file the code sample dosen't work.

What am I missing? Is There a parameter that I need when I use Access 2000?
How To Display an Image from a Database in a Windows Forms PictureBox by
Using Visual Basic .NET
Article ID : 321900 Last Review : July 15, 2004 Revision : 1.0
7. Add the following code in the Click event procedure of Button2:
Dim cn As New SqlConnection(strCn)
Dim cmd As New SqlCommand("SELECT BLOBID, " & _
"BLOBData FROM BLOBTest ORDER BY BLOBID", cn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "BLOBTest")
Dim c As Integer = ds.Tables("BLOBTest").Rows.Count
If c > 0 Then
Dim bytBLOBData() As Byte = _
ds.Tables("BLOBTest").Rows(c - 1)("BLOBData")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)
End If

Nov 22 '05 #3
Hi,

Thanks for you code to repro. I have made some trial on my machine to
reproduce the problem. Finally, when I tried to get pictures from northwind
database, Emplyees table, I get exactly the same exception as yours.

According to the KB article, this test does not work with the Photo column
in the Employees table of the sample Northwind database that is included
with Access and SQL Server. The bitmap images that are stored in the Photo
column are wrapped with the header information that the Visual Basic 6.0
OLE Container control creates.

So could you let me know, how the pictures were stored. I think it's the
byte array data that doesn't match the image object format causes the issue.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #4
Kevin thanks for your help.

The Access database that I need to convert from is currently an Access 2000
database and the photo's were put into the database by dragging and dropping.
The users would drop any format that the original was in. The original data
goes back to 1997 and I have no idea how many Access versions have been used.

My test was on a empty Access 2000 database and I used the drag and drop
method to place a 3 jpg pictures and 1 bmp image into the database. What I
need to do is read the old database and save the old pictures to a file with
an Id that I can reference.

Thanks again for your input.

"Kevin Yu [MSFT]" wrote:
Hi,

Thanks for you code to repro. I have made some trial on my machine to
reproduce the problem. Finally, when I tried to get pictures from northwind
database, Emplyees table, I get exactly the same exception as yours.

According to the KB article, this test does not work with the Photo column
in the Employees table of the sample Northwind database that is included
with Access and SQL Server. The bitmap images that are stored in the Photo
column are wrapped with the header information that the Visual Basic 6.0
OLE Container control creates.

So could you let me know, how the pictures were stored. I think it's the
byte array data that doesn't match the image object format causes the issue.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #5
Hi,

If you have created the photos by dragging and dropping, I think this field
contains OLE header information. So we have to remove it before getting it
to a stream. I have tried the following code on Employees table, Northwind
database. It works well.

DataSet ds = new DataSet();
this.oleDbDataAdapter1.Fill(ds);
byte[] b = (byte[])ds.Tables[0].Rows[0]["Photo"];
MemoryStream m = new MemoryStream(b, 78, b.Length-78); //bmp file's
ole header is 78 bytes long.
Image i = Image.FromStream(m);
this.pictureBox1.Image = i;

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #6
Kevin thanks for your suggestion.

Trimming 78 bytes from the beginning of the memory stream works for bmp
images in my file so there is a header record.
My Access file has a mixture of image types and when I tested a jpg record I
got the same error so a header record for a jpg image must be a different
length.

Do you know what the other image types header sizes are?
Is there a field in the header area to identify the image types?

Thanks again for your help.....

"Kevin Yu [MSFT]" wrote:
Hi,

If you have created the photos by dragging and dropping, I think this field
contains OLE header information. So we have to remove it before getting it
to a stream. I have tried the following code on Employees table, Northwind
database. It works well.

DataSet ds = new DataSet();
this.oleDbDataAdapter1.Fill(ds);
byte[] b = (byte[])ds.Tables[0].Rows[0]["Photo"];
MemoryStream m = new MemoryStream(b, 78, b.Length-78); //bmp file's
ole header is 78 bytes long.
Image i = Image.FromStream(m);
this.pictureBox1.Image = i;

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #7
Hi,

Based on my experience, normally there are only two kinds of image object
which may be inserted into an Access field: the Bitmap image object (BMP
format) and the image document object (TIF format). In the header of the
file, there is string which records the picture's type. For Bitmap image
object, it is "Bitmap Image.Paint.Picture"; for image document object, it
is "Image Document.Imaging.Document". The position 20 is the first char of
the string. We can determine the type of the picture from it. 'B(66) means
Bitmap image object; 'I(73) means image document object. The image
document's header size is 4423 bytes.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #8
Kevin thanks for the response.

I know that my users have dragged and dropped jpg files into the Access
database and I used thee jpg photos in my test database.

When I check position 20 on known jpg photo's I get 'P(80). If I continue
checking the next 31 bytes I get "Photo Editor Photo MSPhotoEd.3"

I have tried to use a header size of 4423 bytes but I get the "Invalid
parameter Used" error.

Do you have any idea's on what the header size should be?

Thanks again for your help....
"Kevin Yu [MSFT]" wrote:
Hi,

Based on my experience, normally there are only two kinds of image object
which may be inserted into an Access field: the Bitmap image object (BMP
format) and the image document object (TIF format). In the header of the
file, there is string which records the picture's type. For Bitmap image
object, it is "Bitmap Image.Paint.Picture"; for image document object, it
is "Image Document.Imaging.Document". The position 20 is the first char of
the string. We can determine the type of the picture from it. 'B(66) means
Bitmap image object; 'I(73) means image document object. The image
document's header size is 4423 bytes.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #9
Wally,

I have been struggling with this exact problem and found this thread
extremely helpful. After reading it I googled "jpg image header size" and
found this which may help you:

http://www.codeproject.com/bitmap/iptc.asp

Thanks to you and Kevin for your posts.

"Wally" wrote:
Kevin thanks for the response.

I know that my users have dragged and dropped jpg files into the Access
database and I used thee jpg photos in my test database.

When I check position 20 on known jpg photo's I get 'P(80). If I continue
checking the next 31 bytes I get "Photo Editor Photo MSPhotoEd.3"

I have tried to use a header size of 4423 bytes but I get the "Invalid
parameter Used" error.

Do you have any idea's on what the header size should be?

Thanks again for your help....
"Kevin Yu [MSFT]" wrote:
Hi,

Based on my experience, normally there are only two kinds of image object
which may be inserted into an Access field: the Bitmap image object (BMP
format) and the image document object (TIF format). In the header of the
file, there is string which records the picture's type. For Bitmap image
object, it is "Bitmap Image.Paint.Picture"; for image document object, it
is "Image Document.Imaging.Document". The position 20 is the first char of
the string. We can determine the type of the picture from it. 'B(66) means
Bitmap image object; 'I(73) means image document object. The image
document's header size is 4423 bytes.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #10
Wally,

I have been struggling with this exact problem and found this thread
extremely helpful. After reading it I googled "jpg image header size" and
found this which may help you:

http://www.codeproject.com/bitmap/iptc.asp

Thanks to you and Kevin for your posts.

"Wally" wrote:
Kevin thanks for the response.

I know that my users have dragged and dropped jpg files into the Access
database and I used thee jpg photos in my test database.

When I check position 20 on known jpg photo's I get 'P(80). If I continue
checking the next 31 bytes I get "Photo Editor Photo MSPhotoEd.3"

I have tried to use a header size of 4423 bytes but I get the "Invalid
parameter Used" error.

Do you have any idea's on what the header size should be?

Thanks again for your help....
"Kevin Yu [MSFT]" wrote:
Hi,

Based on my experience, normally there are only two kinds of image object
which may be inserted into an Access field: the Bitmap image object (BMP
format) and the image document object (TIF format). In the header of the
file, there is string which records the picture's type. For Bitmap image
object, it is "Bitmap Image.Paint.Picture"; for image document object, it
is "Image Document.Imaging.Document". The position 20 is the first char of
the string. We can determine the type of the picture from it. 'B(66) means
Bitmap image object; 'I(73) means image document object. The image
document's header size is 4423 bytes.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 22 '05 #11

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

Similar topics

1
2290
by: Nick | last post by:
How to change the pic to a "show error" image when loading images failed - for example, no image file exists? I tried to add the following statement in the onload event function: if...
9
1966
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
1
3738
by: AA Arens | last post by:
To have the first character of a fiels capitalized AfterUppdate, I used the following script: Me!City = UCase$(Left$(Me!City, 1)) + Mid$(Me!City, 2) UCase (Left(Me!City, 1)) + Mid(Me!City, 2) ...
5
2687
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
1
2965
by: Greg Burns | last post by:
--------------------------- Microsoft Development Environment --------------------------- The Web server reported the following error when attempting to create or open the Web project located at...
2
14234
by: drisso | last post by:
Hello, I have searched that error on these message boards, msdn and crystaldecisions.com. I found tutorials that showed how to export a crystal report to pdf, but like many others I am getting...
3
2570
by: Arnold | last post by:
I am having problem loading the image from the database. It gives this error: "Invalid parameter used." This is my source code: Private abyt() As Byte Private fo As New OpenFileDialog Private sf...
2
4019
by: szechi | last post by:
Greetings, I am facing the following error when trying to use DB2 import command under DB2 version 7.2. SQL3040N Unable to use the lobpath/lobfile parameters as specified. Reason code: "1" ...
7
37995
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement...
3
17112
by: klaritydefect | last post by:
Hi, I am receving the following error when I run my application (build on C ++ code) Program received signal SIGSEGV, Segmentation fault si_code: 1 - SEGV_MAPERR - Address not mapped to...
0
7125
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
7165
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,...
0
7205
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
7379
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
5462
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,...
0
4590
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...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1419
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 ...
0
291
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...

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.