【发布时间】:2014-07-21 00:03:29
【问题描述】:
我正在使用 Visual Studio 2010 创建一个 Windows 应用程序。使用 SQL Server 2008 R2 作为数据库并将图像保存为数据类型 image。上传成功。但我在从数据库中检索图像并将其显示在 PictureBox 中时出现错误 Parameter invalid。
这是我的代码
byte[] pic = ((byte[])dr["image1"]);
Image newImage;
using (MemoryStream ms = new MemoryStream(pic, 0, Convert.ToInt32(pic.Length)))
{
ms.Write(pic, 0, pic.Length);
//Set image variable value using memory stream.
newImage = Image.FromStream(ms, true);
}
//set picture
pictureBox1.Image = newImage;
【问题讨论】:
-
image数据类型将在 SQL Server 的未来版本中删除。避免在新的开发工作中使用此数据类型,并计划修改当前使用它们的应用程序。请改用varbinary(max)。 See details here
标签: visual-studio-2010 c#-4.0 sql-server-2008-r2