Solved

Passing a BLOB as a  longvarbinary parameter to a stored proc ?

Posted on 2004-09-30
3
1,944 Views
Last Modified: 2013-12-25
Hi,

I'm having problems passing a byte array to a stored proc as a longvarbinary.
The sample code that follows throws an error:
"Application uses a value of the wrong type for the current operation."
when I attempt to append a chunk.

Any ideas?


Public Function AddLongBin() As Boolean

    Dim cmd As New ADODB.Command
    Dim prmID As ADODB.Parameter
    Dim prmBin As ADODB.Parameter
    Dim aBin() As Byte

   
On Error GoTo ErrHandler

    cmd.ActiveConnection = cnDatabase
    cmd.CommandText = "AddLongBin"
    cmd.CommandType = adCmdStoredProc
   
    ReDim aBin(100) As Byte
   
    Set prmBin = cmd.CreateParameter("Bin", adLongVarBinary, adParamInput, 100)
    cmd.Parameters.Append prmBin
   
    prmBin.Attributes = adFldLong
    prmBin.AppendChunk aBin
   
    cmd.Execute

ErrHandler:
    If Err.Number <> 0 Then
        MsgBox Err.Description
        Err.Clear
    End If
   

End Function
0
Comment
Question by:aregan
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Alan Warren earned 20 total points
ID: 12234488
Heres one I use maybe it will help you.
The thing I see as different is the defined size for you blob parameter.
http://www.able-consulting.com/ADODataTypeEnum.htm



  with cmd
    ' zips are stored in another table so use different stored query
    If sFileExtension = "zip" Then
        .CommandText = "spJetPackBlob_zip"
    Else
      .CommandText = "spJetPackBlob"
    End If      
    .CommandType = adCmdStoredProc        
      .Parameters.Append .CreateParameter("pFileName", adVarChar, adParamInput, 255, sFileName)
      .Parameters.Append .CreateParameter("pFileType", adVarChar, adParamInput, 255, sFileType)
      .Parameters.Append .CreateParameter("pDateCreated", adDBTimeStamp, adParamInput, 8, dDateCreated)
      .Parameters.Append .CreateParameter("pDateLastAccessed", adDBTimeStamp, adParamInput, 8, dDateLastAccessed)
      .Parameters.Append .CreateParameter("pFileSize", adInteger, adParamInput, 4, lFileSize)
      .Parameters.Append .CreateParameter("pFileExtension", adVarChar, adParamInput, 255, sFileExtension)
      .Parameters.Append .CreateParameter("pFileBinary", adLongVarBinary, adParamInput,2147483647, oFileBinary)
    Set .ActiveConnection = cn
    .Execute
  end with


Might find some usefull information and samples relating to using blobs here too:
http://www26.brinkster.com/alzowze/blobs.asp


Alan
0
 

Author Comment

by:aregan
ID: 12235378
Thanks Alan

Just figured this out last nite. Your right - it was the paremeter length that was throwing it out.

Alan.
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12235399
Thanks Alan,

you know you can actually set the param size to the len(oFileBinary)

.Parameters.Append .CreateParameter("pFileBinary", adLongVarBinary, adParamInput,len(oFileBinary), oFileBinary)

Alan :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question