错误“使用的参数无效“当我尝试显示图像时 [英] Error " Invalid Parameter Used" when I try to display an image

查看:109
本文介绍了错误“使用的参数无效“当我尝试显示图像时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示来自Access 2000数据库的图像,但我收到错误

使用的参数无效当我执行代码行时

" picBLOB.Image = Image.FromStream(stmBLOBData)"在我的Visual Basic .Net

应用程序中。


我已经研究过MSDN求助,并找到了示例文章321900(参见

下面)并设置一个测试,当我使用SQL Server 2000

时,一切正常,但当我修改代码并使用

" OleDbDataAdapter& ;我收到了错误。


我尝试通过将我的Access 2000数据库导入SQL Server

数据文件来解决问题我使用了示例代码。如果我将一张图片加载到一个SQL Server文件中并使用它可以使用的代码示例,但如果我将相同的图片文件加载到Access 2000文件中,那么代码示例不起作用。


我缺少什么?我使用Access 2000时是否需要一个参数?

如何通过

使用Visual Basic .NET从Windows窗体PictureBox中的数据库显示图像

文章编号:321900最后修改:2004年7月15日修订:1.0

7.在Button2的Click事件过程中添加以下代码:

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

如果c> 0然后

Dim bytBLOBData()As Byte = _

ds.Tables(" BLOBTest")。Rows(c - 1)(" BLOBData")

Dim stmBLOBData As New MemoryStream(bytBLOBData)

picBLOB.Image = Image.FromStream(stmBLOBData)

结束如果

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

推荐答案




首先,我想确认一下我对你的问题的理解。从

您的描述中,我了解到您正在尝试根据KB文章从

Access 2000数据库中获取图片。如果有任何

的误解,请随时告诉我。


现在让我们专注于从Access 2000获取数据而不是导入数据
SQL Server中的
。首先,请将System.Data.OleDb命名空间中的Sql对象更改为OleDb

对象以支持Access。然后尝试再次运行该代码
。代码似乎很好,我认为可能有一些与数据库表不匹配的b $ b不匹配。你能不能告诉我哪一行?
应用停止并抛出异常?


Kevin Yu

=== ====

此帖子已提供按现状没有保证,并且不授予

权利。

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."


对不起,我在第一篇帖子中包含的代码是我测试SQL数据时跟随的例子是
。这是我在使用的时候使用的代码
尝试从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")。行(bmbRptData.Pos ition)

c = bmbRptData.Position


curRow.BeginEdit()


MyPermit_No = curRow(" Permit_No")


如果c> = 0则

尝试


Dim bytBLOBData()As Byte = _


DsMyTest1.Tables(" MyTestData")。行(c)(Sign_Photo)


Dim stmBLOBData As New MemoryStream(bytBLOBData )


''代码跳转到异常捕获与

''ex3.message ="使用的参数无效"

''当我运行下一行时


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,未处理的异常错误)


最后



Wally写道:
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:
我试图从Access 2000数据库显示图像,我收到一个错误
使用的参数无效当我执行代码行时,
picBLOB.Image = Image.FromStream(stmBLOBData)在我的Visual Basic .Net
应用程序中。

我已经研究过MSDN求助,并找到了示例文章321900(参见下面的
)并设置了测试,一切正常我使用SQL Server 2000
但当我修改代码并使用来自Access 2000的数据时使用
OleDbDataAdapter我收到了错误。

我尝试将我的Access 2000数据库导入SQL Server数据文件,并使用示例代码得到相同的错误。如果我将图片
(jpg)加载到SQL Server文件中并使用代码示例它可以工作,但如果我将相同的图片文件加载到Access 2000文件中代码示例本身不起作用。

我错过了什么?我使用Access 2000时是否需要一个参数?

如何通过使用Visual Basic .NET从Windows窗体PictureBox中的数据库显示图像
文章ID :321900最后修改:2004年7月15日修订:1.0
7.在Button2的Click事件过程中添加以下代码:
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然后
Dim bytBLOBData()As Byte = _
ds.Tables(" BLOBTest")。Rows(c - 1)(" BLOBData")
Dim stmBLOBData As New MemoryStream( bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)
结束如果
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





感谢您重新编写代码。我已经在我的机器上进行了一些试验,以便

重现问题。最后,当我试图从北风获取图片时,我会得到与你一样的例外情况。我会得到与你相同的例外情况。


根据知识库文章,此测试不适用于示例Northwind数据库的Employees表中的Photo列

,其中包含带有Access和SQL Server的
。存储在Photo

列中的位图图像包含Visual Basic 6.0

OLE容器控件创建的标题信息。


所以你能让我知道,图片是如何存储的。我认为这是与图像对象格式不匹配的

字节数组导致问题。


HTH。


Kevin Yu

=======

此帖子已提供按现状没有保证,也没有赋予

权利。

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."


这篇关于错误“使用的参数无效“当我尝试显示图像时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆