这里的图片存在数据表的形式为十六进制的数据,参数ds为从数据库中选出的DataSet,字段FImage为图片字段。
private void getPicture(DataSet ds) { //int Pictured = dataGridView1.FocusedRowHandle; int rid=dataGridView1.CurrentRow.Index; string HasPicture = ds.Tables[0].Rows[rid]["FImage"].ToString(); if (HasPicture !="") { Byte[] byteBLOBData = new Byte[0]; byteBLOBData = (Byte[])(ds.Tables[0].Rows[rid]["FImage"]); MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); pictureBox1.Image = Image.FromStream(stmBLOBData); } else { pictureBox1.Image = null; } }