怎样用从SQL中将image字段保存的图片读出来?
并且显示在Label的Image中!

解决方案 »

  1.   

    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,

    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);}
      

  2.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=ECD9AE16-8FF0-4A1C-9B9F-5E8B641CB1B1
      

  3.   

    DataSet ds=Stub.GetInstance().GetDataSet1("select pat_pict from patientpict where pat_no='"+sPatno+"'","a");
    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();
    }
      

  4.   

    怎么没有label1.Image属性呢???????????//