0

我已使用以下代码使用 LINQ 绑定 datagridview,但未显示图像字段。

var query = r.GetTable<Subcategory>().ToList();

List<subcategory> l = new List<subcategory>();
foreach (var s in query)
{
    subcategory s1 = new subcategory();
    s1.sub_id = s.sub_id;
    s1.sub_name = s.sub_name;
    s1.sub_image =s.sub_image;
    s1.sub_catid = s.cat_id;
    l.Add(s1);
}

griditems.AutoGenerateColumns = true;
griditems.DataSource = l;

图像字段为二进制格式。它没有显示,但其余字段正在显示。

4

1 回答 1

0

You should use Image data type instead byte[]. You can convert byte[] to Image by this code:

public Image ByteArrayToImage(byte[] imageBytes)
{
     System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}
于 2013-05-25T14:51:55.773 回答