check out the sample for PictureBox, it should be very similarHOW TO:在 Visual C# 中直接将一个图片从数据库复制到 PictureBox 控件 http://support.microsoft.com/kb/317701/Zh-CN/try { SqlConnection cn = new SqlConnection(strCn); cn.Open(); //Retrieve BLOB from database into DataSet. SqlCommand cmd = new SqlCommand("SELECT BLOBID, BLOBData FROM BLOBTest ORDER BY BLOBID", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "BLOBTest"); int c = ds.Tables["BLOBTest"].Rows.Count; if(c>0) { //BLOB is read into Byte array, then used to construct MemoryStream,
http://support.microsoft.com/kb/317701/Zh-CN/try
{
SqlConnection cn = new SqlConnection(strCn);
cn.Open(); //Retrieve BLOB from database into DataSet.
SqlCommand cmd = new SqlCommand("SELECT BLOBID, BLOBData FROM BLOBTest ORDER BY BLOBID", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "BLOBTest");
int c = ds.Tables["BLOBTest"].Rows.Count; if(c>0)
{ //BLOB is read into Byte array, then used to construct MemoryStream,
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["BLOBData"]);
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); Image image1 =Image.FromStream(stmBLOBData);label1.Size = new Size(image1.Width, image1.Height); label1.Image = image1;
}
cn.Close();
}
catch(Exception ex)
{MessageBox.Show(ex.Message);}
if(ds!=null && ds.Tables[0].Rows.Count >0)
{
string sFilename = "C:\\1.bmp";
FileInfo fi = new FileInfo(sFilename);
FileStream myStream=fi.Open(FileMode.Create);
byte[] mydata=((byte[])ds.Tables[0].Rows[0]["pat_pict"]);
foreach(byte a in mydata)
{
myStream.WriteByte(a);
}
myStream.Close();
Image myImage=Image.FromFile(sFilename) ;
this.pictureBox1.Image=myImage;
this.pictureBox1.Refresh();
}