CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2001
    Posts
    28

    ADO and Blob column

    My issue is about Oracle 8i and Visual Basic. I'm using ADO 2.5 and OLEDEB.

    I want to store into the database ( BLOB column) the content of a Picture
    File. How
    can I do it?

    Could you have a little pice of code to show hot to store and get this picture
    to and from the database?

    Can I save to the hard disk (of the client machine) the value of this BLOB
    column?


    Chandar


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: ADO and Blob column

    You can find an example to do this with SQL server at the microsoft site. The thing you need to change to use it for oracle is thet part when establishing the connetion. But the AppendChunk and GetChunk methods work the same.

    http://support.microsoft.com/support.../3/68.asp?FR=0

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: ADO and Blob column

    Save picture to DB

    Const MAX_PATH = 255
    private Const CHUNK_SIZE = 1000
    private Declare Function GetTempPath Lib "kernel32" _
    Alias "GetTempPathA" (byval nBufferLength as Long, _byval lpBuffer as string) as Long
    public Function SavePictureToDB(PictControl as Object, _
    RS as Object, FieldName as string) as Boolean

    'PURPOSE: SAVES PICTURE IN IMAGEBOX, PICTUREBOX, OR SIMILAR
    'CONTROL to RECORDSET RS IN FIELD NAME FIELDNAME
    'FIELD TYPE MUST BE binary (OLE OBJECT IN ACCESS)

    'SAMPLE USAGE
    'Dim sConn as string
    'Dim oConn as new ADODB.Connection
    'Dim oRs as new ADODB.Recordset''
    'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.MDB;Persist Security Info=false"'
    'oConn.Open sConn
    'oRs.Open "SELECT * FROM MYTABLE", oConn, adOpenKeyset, _
    adLockOptimistic
    'oRs.AddNew
    'SavePictureToDB Picture1, oRs, "MYFIELD"
    'oRs.Update
    'oRs.Close

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: ADO and Blob column

    Load from DB

    public Function LoadPictureFromDB(PictControl as Object, _
    RS as Object, FieldName as string) as Boolean
    'PURPOSE: LOADS PICTURE, SAVED as binary DATA IN RECORDSET RS,
    'FIELD FieldName to PICTUREBOX, IMAGEBOX (OR CONTROL'WITH SIMILAR INTERFACE)

    'SAMPLE USAGE
    'Dim sConn as string
    'Dim oConn as new ADODB.Connection
    'Dim oRs as new ADODB.Recordset'
    ''sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.MDB;Persist Security Info=false"'
    'oConn.Open sConn'oRs.Open "SELECT * FROM MyTable", oConn, adOpenKeyset, adLockOptimistic
    'LoadPictureFromDB Picture1, oRs, "MyFieldName"
    'oRs.Close

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Jul 2001
    Posts
    28

    Re: ADO and Blob column

    Where is the definition of LoadPicturefromDB and SavePicturetoDB ?





  6. #6
    Join Date
    Jan 2006
    Posts
    1

    Wink Re: ADO and Blob column

    This simple Visual Basic form does two things saves a blob file and opens and displays the blob file. Regardless of what DB you are using retrieving and saving the "string data (the blob)" should not be an issue.

    Start a VB project > Standard EXE
    Add a RichText control to the form named RichText
    Create two menu items Open (mnuOpen) and Save (mnuSave)
    Copy and paste this code into the form.

    Private Sub Form_Resize()
    RichText.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
    End Sub
    Private Sub mnuOpen_Click()
    Dim SourceFile As Long
    Dim FileLength As Long
    Dim StringData As String
    SourceFile = FreeFile
    Open "MyBLOB" For Binary Access Read As SourceFile
    FileLength = LOF(SourceFile)
    If FileLength = 0 Then
    MsgBox "MyBLOB Empty or Not Found."
    Else
    StringData = String(FileLength, 0)
    Get SourceFile, , StringData
    RichText.TextRTF = StringData
    End If
    Close SourceFile
    End Sub
    Private Sub mnuSave_Click()
    Dim FileNum As Long
    Dim sRichText As String
    FileNum = FreeFile
    Open "MyBLOB" For Binary As FileNum
    sRichText = RichText
    Put FileNum, , sRichText
    Close FileNum
    MsgBox "BLOB Saved"
    End Sub

    Save the project!
    Run the project

    Open your favorite word processor. Type in some text using bold, underline, etc., insert a picture into the document.

    Highligt the entire document content (Select All) and Copy.

    Paste the information into the RichText control.

    Click on Save menu item. The blob has been saved to file MyBLOB.

    Exit and close the VB project.

    Open the VB project.

    Click the Open menu item. Whoala!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured