【发布时间】:2020-04-02 19:32:02
【问题描述】:
我在 C# 中有一个动态图片框,它从数据表的列中获取图片 数据表结构为:
public DataTable Pictures = new DataTable();
Pictures.Columns.Add("id", typeof(bool));
Pictures.Columns.Add("filebytes", typeof(SqlBinary));
我有一个字节数组在图片框中显示图片:
byte[] ImageBinary;
以下代码用于显示图像:
PictureBox a = new PictureBox();
a.Location = new Point(100, 90);
a.Size = new Size(25, 25);
a.SizeMode = PictureBoxSizeMode.StretchImage;
groupBox3.Controls.Add(a);
MemoryStream ms = null;
Image img = null;
Tools b = new Tools();
ImageBinary = b.CreateImageBinary(openFileDialog1.FileName);
ms = new MemoryStream(ImageBinary);
Pictures.Rows.Add(new object[] { i, ImageBinary });
img = Image.FromStream(ms);
a.Image = img;
ms.Close();
它从 Openfiledialog 获取图像
我想从数据表中为图片框赋值我的问题是当我像这样更改代码时:
ImageBinary = (byte[])Pictures.Rows[sm][1]; //sm is a variable to specific a row of datatable
它让我出错:
无法将“system.data.sqltypes.sqlbinary”类型的对象转换为类型 'system.byte[]'
我很困惑,请帮帮我
【问题讨论】:
标签: c# winforms datatable sql-types