界面上一个datagirdview 和一个pictruebox  现在我选中一行 想把里面的图片显示到piturebox 如何实现?
是mysql 数据库!

解决方案 »

  1.   

    转到MySQL社区吧!语法不同。不过原理差不多。
      

  2.   


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