BLOB - Retieve image stored in database
[code=vb]
Dim CN As New ADODB.Connectio n
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
Private Const ChunkSize As Integer = 16384
Private Const conChunkSize = 100
Private Sub Form_Load()
CN.Open "Provider=SQLOL EDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Da ta Source=Test"
Dim strsql As String
strsql = "SELECT * FROM pub_info where pub_id = '9999'"
RS.Open strsql, CN, adOpenForwardOn ly, adLockReadOnly
ShowPic
Set RS = Nothing
Set RS = New Recordset
End Sub
Private Sub ShowPic()
DataFile = 1
Open "pictemp" For Binary Access Write As DataFile
Fl = RS!logo.ActualS ize ' 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.GetChun k(Fragment)
Put DataFile, , Chunk()
For i = 1 To Chunks
ReDim Buffer(ChunkSiz e)
Chunk() = RS!logo.GetChun k(ChunkSize)
Put DataFile, , Chunk()
Next i
Close DataFile
FileName = "pictemp"
Picture1.Pictur e = LoadPicture(Fil eName)
End Sub
[/code]
[code=vb]
Dim CN As New ADODB.Connectio n
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
Private Const ChunkSize As Integer = 16384
Private Const conChunkSize = 100
Private Sub Form_Load()
CN.Open "Provider=SQLOL EDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Da ta Source=Test"
Dim strsql As String
strsql = "SELECT * FROM pub_info where pub_id = '9999'"
RS.Open strsql, CN, adOpenForwardOn ly, adLockReadOnly
ShowPic
Set RS = Nothing
Set RS = New Recordset
End Sub
Private Sub ShowPic()
DataFile = 1
Open "pictemp" For Binary Access Write As DataFile
Fl = RS!logo.ActualS ize ' 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.GetChun k(Fragment)
Put DataFile, , Chunk()
For i = 1 To Chunks
ReDim Buffer(ChunkSiz e)
Chunk() = RS!logo.GetChun k(ChunkSize)
Put DataFile, , Chunk()
Next i
Close DataFile
FileName = "pictemp"
Picture1.Pictur e = LoadPicture(Fil eName)
End Sub
[/code]