닷넷/C#

C# DB에 이미지가 16진수로 저장되어 있을 때

FreeBear 2016. 12. 7. 09:54
반응형
텍스트 파일에 저장되어 있는 것보다 간단하다.

connection 부분과 command 부분은 뺐습니다.


conn.Open();
                    
SqlDataReader reader = comm.ExecuteReader();
 
byte[] bImage = null;
while (reader.Read())
{
    bImage = (byte[])reader["Picture"]; // 이미지가 hex string으로 저장되어 있는 칼럼명
}
 
if (bImage != null)
{
    pictureBox1.Image = new Bitmap(new MemoryStream(bImage));
}
reader.Close();
conn.Close();
cs


반응형