dr.Read(); System.Data.SqlTypes.SqlBinary sb = dr.GetSqlBinary(2); //或byte[] imageData = (byte[])dr[2]; //FileStream fs = new FileStream(@"C:\temp.bmp",FileMode.Create); string filename = @"C:\" + System.IO.Path.GetFileName(dr.GetString(1)); FileStream fs = new FileStream(filename,FileMode.Create); fs.Write(sb.Value,0,sb.Value.Length); fs.Close(); //this.pictureBox1.Image = Image.FromFile(@"C:\temp.bmp"); System.Diagnostics.Process.Start(filename); dr.Close(); } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } } } }
直接把整个文件读取到内存中的数组里对于小文件来说是没问题的,但如果是大文件,特别是大小都超过了物理内存的文件,可能会导致严重的内存问题,需要分段读取,并分段写到数据库。
http://maxianghui.cnblogs.com/archive/2006/07/12/448943.html 上一页 [1] [2] [3] [4] [5] [6] |