我想检索保存为数据库中的blobtyped数据的图像。如何获取它并将其保存到Image / Bitmap对象中?
答案 0 :(得分: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();
}
}
}
}
这就是我的开始。当然,这里缺少错误检查,我不保证立即编译: - )