How to Read Image from Data Base which is stored in Binary format.
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 'Database - How to Read Image from Data Base which is stored in Binary format. Option Explicit Dim cn As New ADODB.Connection Dim rs As ADODB.Recordset Dim DataFile As Integer, Fl As Long, Chunks As Integer Dim Fragment As Integer, Chunk() As Byte, I As Integer, FileName As String Const ChunkSize As Integer = 16384 Const conChunkSize = 100 Private Sub Form_Load() cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test" Dim strsql As String Set rs = Nothing Set rs = New Recordset strsql = "SELECT * FROM pub_info where pub_id = '9999'" rs.Open strsql, cn, adOpenForwardOnly, adLockReadOnly ShowPic End Sub Private Sub ShowPic() DataFile = 1 Open "pictemp" For Binary Access Write As DataFile Fl = rs!logo.ActualSize ' Length of data in file If Fl = 0 Then Close DataFile: Exit Sub Chunks = Fl \ ChunkSize Fragment = Fl Mod ChunkSize ReDim Chunk(Fragment) Chunk() = rs!logo.GetChunk(Fragment) Put DataFile, , Chunk() For I = 1 To Chunks ReDim Buffer(ChunkSize) Chunk() = rs!logo.GetChunk(ChunkSize) Put DataFile, , Chunk() Next I Close DataFile FileName = "pictemp" Picture1.Picture = LoadPicture(FileName) End Sub |