How to use the adArray parameter in ADO command object

Posted on 2005-04-20
Last Modified: 2012-08-13
Hello experts,

My question seems to be a very common scenario, but i was unable to find an answer from the net. I have a VB array that needs to inserted into an oracle table. I need to pass this array as a parameter to a stored procedure. Somebody please help me out with a sample code. Also how should i declare the parameter in oracel to accept this array ?

Question by:TheHartford
    LVL 38

    Expert Comment

    What kind of array is it?  String, integer, byte?

    Author Comment

    Its a combination of String and Integer array
    LVL 38

    Expert Comment

    In otherwords a variant array?

    Author Comment

    You could say that...the reason is i want to call the stored procedure only once from my VB code but execute the array the number of times it has the elements in the backend

    LVL 38

    Expert Comment

    Execute the array?  What does that mean exactly?  What's being stored in the array, and where is the data going in the database?  Single field, multiple fields?  

    If you want to combine multiples of different type values into a single field, I suggest you use a format like XML.  If they are going to separate fields, but you want to limit the number of trips to the database, I would suggest a batch update instead.
    LVL 9

    Expert Comment

    by:Naveen Swamy

    Public Function ExecuteSP(ByVal sProcName As String, ParamArray aParams()) As ADODB.Recordset

        Dim cmd As ADODB.Command
        Dim cmdParam As New ADODB.Parameter
        Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = gConn
        cmd.CommandText = sProcName
        cmd.CommandType = adCmdStoredProc
        If UBound(aParams) < 0 Then
            ' if NO parameters to execute the sp
            Set ExecuteSP = cmd.Execute
            ' if we use parameters to execute the sp
            Set ExecuteSP = cmd.Execute(, aParams)
        End If
        Set cmd = Nothing
    '    Exit Function
    '    MsgBox "Error: " & vbCrLf & "Reason: " & Err.Description, vbCritical + vbSystemModal, gAppTitle
    ''    Resume
    '    Exit Function
    End Function

    first parameter to call the stored procedure and then the second is a list of arrays (can be string or integer)

        Set grsTemp = ExecuteSP("SSP_INSERT_RELATIONSHIPLIST", strMainId, sCurrentTableName, iPrevID, sPrevFldName, sFldOrderVal)

    M.Naveen Swamy
    LVL 38

    Expert Comment

    I think the reason he was unable to find his answer on the Internet is because it is not possible to pass an array of values as a single parameter.  I believe the adArray datatype is to support the possibility of data access drivers that would support an array datatype.  The correct workaround depends on what you are trying to acheive.

    PRB: Microsoft Oracle OLEDB Provider and ODBC Drivers Do Not Support Passing Array Data Types;en-us;298965


    Accepted Solution

    PAQed with no points refunded (of 100)

    Community Support Moderator

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    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…
    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…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now