2012-03-27 10 views
0

データベースにブロブ型データとして保存されたイメージを取得したいと思います。どうすればそれを取得し、それをImage/Bitmapオブジェクトに保存できますか?イメージタイプのブロブ記憶

+0

http://stackoverflow.com/questions/9652634/c-sharp-reading-blob-from -sql-server-and-picture-box – Habib

+0

どのデータベースですか? SQL Server、Oracle、MySQL? – CAbbott

答えて

0
using (SqlConnection conn = new SqlConnection(...)) 
{ 
    conn.Open(); 

    using (SqlCommand cmd = new SqlCommand("SELECT BlobFieldName FROM Table ...", conn); 
    using (SqlDataReader reader = cmd.ExecuteReader()) 
    { 
     if (reader.Read()) 
     { 
      byte[] bytes = reader["BlobFieldName"] as byte[]; 

      using (FileStream stream = new FileStream(...)) 
      { 
       stream.Write(bytes, 0, bytes.Length); 
       stream.Flush(); 
      } 
     } 
    } 
} 

これは私が始めているものです。もちろん、ここではエラーチェックが行なわれていないので、すぐにコンパイルできるとは保証しません:-)

関連する問題