?
Solved

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

Posted on 2004-09-30
3
Medium Priority
?
2,026 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Alan Warren earned 60 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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