VB / SQL Binary or Image ?

  • Wenck

    SSC Enthusiast

    Points: 158

    Hi,

    I'm trying to write an application which does the following.

    1) A user drags an item (could be Email, Word, Excel, Picture, etc) and drops it on an OLE Container.

    2) When they click a Button, this then INSERTs the object into a SQL Server database table.

    3) Another form, needs to be able to retrieve this object into an OLE container, so the user can double click on it to view it.

    I can get step 1 to work no worries. It's just the second step where I'm having issues.

    With this code that I'm using I get a String or Binary will be truncated error. I've made the SQL field, a Binary and a VarBinary with no success.

    [vbcode]

    fd = FreeFile

    Open OLE1.SourceDoc For Binary Access Read As fd

    flen = LOF(fd)

    If flen = 0 Then

    Close

    MsgBox "Error while opening the file"

    End

    End If

    Set object = mcmdCurrent.CreateParameter("item", adLongVarBinary, adParamInput, flen + 100)

    ReDim chunk(1 To flen)

    Get fd, , chunk()

    ' Insert the object into the parameter object

    object.AppendChunk chunk()

    mcmdCurrent.Parameters.Append object

    ' Now execute the command

    Set rs = mcmdCurrent.Execute

    [/vbcode]

    Any ideas ? Am I on the right track ? I'm really bashing my head against the wall on this one. I've search hundreds of web pages with no success.

  • Wenck

    SSC Enthusiast

    Points: 158

    Damn ... it got posted twice ... and i can't remove it 🙁

  • Andy Warren

    SSC Guru

    Points: 119694

    Close, but I'd recommend using the stream object rather than the chunk you're using, it will read it from disk for you. Search MSDN for ADO STREAM. I'll work on getting some sample code posted. No sweat on the double post, I'll remove the extra one.

    Andy

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply