C#如何读取数据库中所有的图片显示到对应的pictureBox中

2025-04-17 10:47:51
推荐回答(1个)
回答(1):

private void ShowImage(string sql)
     {
     //调用方法如:ShowImage("select Photo from UserPhoto where UserNo='" + userno +"'");
     SqlCommand cmd = new SqlCommand(sql, conn);
     conn.Open();
     byte[] b= (byte[])cmd.ExecuteScalar();
     if (b.Length 〉 0)
     {
     MemoryStream stream = new MemoryStream(b, true);
     stream.Write(b, 0, b.Length);
      pictureBox1.Image = new Bitmap(stream);
      stream.Close();
     }
     conn.Close();
     }

类似这样 根据你的实际情况修改。