创建一个BtnShow按钮,然后添加以下代码:
 private void BtnShow_Click(object sender, System.EventArgs e)
  {
    SqlConnection conn=new SqlConnection(ConnectString); 

     string strSql="SELECT Photo from Picture where StudentID="1:;

     SqlCommand cmd=new SqlCommand(strSql,conn);

      conn.Open();
      SqlDataReader reader=cmd.ExecuteReader();
       reader.Read();

         MemoryStream ms=new MemoryStream((byte[])reader["Photo"]);  //创建一个内存   读取数据流,将读取的数据库的图片以二进制的byte[]流存入内存中。
           
   reader.Close();
   conn.Close();
   

   StudentPhoto.Image=Image.FromStream(ms,true); //从刚才存储到内存的数据流中创建Image对象。
   StudentPhoto.SizeMode=PictureBoxSizeMode.CenterIma;
}

Posted on 2006-08-09 11:49  李通通  阅读(3481)  评论(12编辑  收藏  举报