Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Unanswered: Inserting pictures in DB - For VB programmers

    Private conn As ADODB.Connection
    Private rs As ADODB.Recordset

    Private Sub ConnectToDB()

    Dim strData As String

    'Establish the connection.
    Set conn = New ADODB.Connection
    Call conn.Open("driver={SQL Server};server=srv_scgb\scg_sgbd;uid=tdela;pwd=pas sword;database=Mercure_tst")

    'Open the recordset
    Set rs = New ADODB.Recordset

    'Make sure you don't retrieve any data !!!
    Call rs.Open("Select * From Images Where FileName='0'", _
    conn, _
    adOpenKeyset, _
    adLockOptimistic)

    Call SaveToDB

    Call rs.Close
    Call conn.Close

    Set rs = Nothing
    Set conn = Nothing

    End Sub

    Private Sub SaveToDB()

    Dim bytBLOB() As Byte
    Dim strImagePath As String
    Dim intNum As Integer

    'Save the record
    strImagePath = Trim("c:\windows\bureau\MyImage.bmp")

    With rs
    'Open the picture file
    intNum = FreeFile
    Open strImagePath For Binary As #intNum
    ReDim bytBLOB(FileLen(strImagePath))

    'Read data and close file
    Get #intNum, , bytBLOB
    Close #1

    Call .AddNew
    .Fields("FileName") = "The image title"
    Call .Fields("Picture").AppendChunk(bytBLOB)
    Call .Update
    End With

    End Sub

  2. #2
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Re: Inserting pictures in DB - For VB programmers

    Table name >>> Images
    Column 1 >>> FileName varchar(50)
    Column2 >>> Pisture image(16)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •