Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vb.net中显示图像_Vb.net - Fatal编程技术网

在vb.net中显示图像

在vb.net中显示图像,vb.net,Vb.net,我试图在SQL Server中显示保存的图像,但它给我一个错误,显示“参数无效” 您可以将该代码合并为以下内容: While oDataReader.Read() TextBox1.Text = oDataReader("nombre") Dim mStream As New IO.MemoryStream(oDataReader("imagen")) PictureBox1.Image = Image.FromStream(mStream) End While 这里的

我试图在SQL Server中显示保存的图像,但它给我一个错误,显示“参数无效”


您可以将该代码合并为以下内容:

While oDataReader.Read()
    TextBox1.Text = oDataReader("nombre")
    Dim mStream As New IO.MemoryStream(oDataReader("imagen"))
    PictureBox1.Image = Image.FromStream(mStream)
End While

这里的主要修复方法是使用
图像
而不是
位图
。如果您知道只有一条记录,则应将
While
更改为
if
。如果您可能有多条记录,则需要完全重新考虑用户界面中的某些内容。

“给出错误”没有帮助。阅读本文并学习如何编写一个我也认为很多代码应该在While循环之外。
Convert.ToInt32(imagenbyte.Length)
-为什么???只是为什么
imagenbyte.Length
已经是一个
Int32
!(也称为
Integer
如果是oDataReader.Read(),则可能是
@LarsTech。但我怀疑阅读图像不是这里唯一的问题。可能有不止一条记录需要处理,OP还需要弄清楚如何使用网格、flowlayoutpanel或类似工具。一步一个脚印。@LarsTech加上“while”,它将以最后一个图像结束,而“if”将以第一个图像结束。这假设可以有多个返回的图像。是的,我想我要进行更改。而且部分代码不起作用MemoryStream@the_lotus基于文本框和图片框以及声明“我正在尝试显示保存的图像”的OP,代码的“意图”显然是只显示一个字符串和一个图像。数据库查询调用应该将数据过滤到一个记录中,因此,if条件更合适。
While oDataReader.Read()
    TextBox1.Text = oDataReader("nombre")
    Dim mStream As New IO.MemoryStream(oDataReader("imagen"))
    PictureBox1.Image = Image.FromStream(mStream)
End While