BLOB - Save image to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    BLOB - Save image to database

    BLOB - Save image to database

    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.

    [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 cmdSave_Click()
    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, adLockOptimisti c

    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.AppendC hunk Chunk()
    ReDim Chunk(ChunkSize )
    For i = 1 To Chunks
    Get DataFile, , Chunk()
    RS!logo.AppendC hunk Chunk()
    Next i
    Close DataFile
    End Sub
    [/code]
    Last edited by debasisdas; Nov 20 '07, 07:25 AM. Reason: Formatted using code=vb tags.
Working...