BLOB's are a way of storing images in a database. The following procedure will show you how to create a connection to your database and how to store an image using BLOB.
Expand|Select|Wrap|Line Numbers
- 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
- Private Const ChunkSize As Integer = 16384
- Private Const conChunkSize = 100
- Private Sub cmdSave_Click()
- CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test"
- Dim strSQL As String
- strSQL = "SELECT * FROM pub_info where pub_id = '9999'"
- RS.Open strSQL, CN, adOpenForwardOnly, adLockOptimistic
- RS.AddNew
- SavePicture
- RS.Update
- Set RS = Nothing
- Set RS = New Recordset
- End Sub
- Private Sub SavePicture()
- Dim strFileNm As String
- DataFile = 1
- Open strFileNm For Binary Access Read As DataFile
- Fl = LOF(DataFile) ' Length of data in file
- If Fl = 0 Then Close DataFile: Exit Sub
- Chunks = Fl \ ChunkSize
- Fragment = Fl Mod ChunkSize
- ReDim Chunk(Fragment)
- Get DataFile, , Chunk()
- RS!logo.AppendChunk Chunk()
- ReDim Chunk(ChunkSize)
- For i = 1 To Chunks
- Get DataFile, , Chunk()
- RS!logo.AppendChunk Chunk()
- Next i
- Close DataFile
- End Sub