我使用以下代码。

foreach (DataRow dr1 in dt.Rows)
{
   picbyte = (byte[])dr1["AssociateImageData"];
   Stream stream = new MemoryStream(picbyte);
   pictureBox1.Image =Image.FromStream(stream,true,true);
}

最佳答案

尝试这样:

var da = new SqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds, "AssociateImageData");
int count = ds.Tables["AssociateImageData"].Rows.Count;

if (count > 0)
{
    var picbyte = (Byte[])(ds.Tables["AssociateImageData"].Rows[count - 1]["AssociateImageData"]);
    var stream = new MemoryStream(picbyte);
    pictureBox1.Image= Image.FromStream(stream);
}

09-28 06:53