Microsoft访问c#picturebox

时间:2016-02-14 19:04:36

标签: c#

当我连接到C#表单时,一切正常,但我无法将附件文件连接到图片框。我收到了一条包含此文字的错误消息框:Index was outside the bounds of the array.

enter image description here

byte[] imageBytes = (byte[])reader.GetValue(6);
MemoryStream ms = new MemoryStream();
ms.Write(imageBytes, 0, imageBytes.Length);
Bitmap p = new Bitmap(Image.FromStream(ms));
poto.Image = p;

1 个答案:

答案 0 :(得分:0)

尝试直接从流

分配图像
byte[] imageBytes = (byte[])reader.GetValue(6); 
comm = new OleDbCommand(sqlCommand, sqlConnection);
ImageByte = comm.ExecuteScalar();
MemoryStream ms = new MemoryStream(ImageByte);
poto.Image = Image.FromStream(ms);

如果您仍然收到错误:

  

无法转换类型为' system.string'的对象输入' system.byte []'

也许你的SQL查询有问题。调试并检查输出

MessageBox.Show(reader.GetValue(6).ToString());