Advertisement

10.17.2003 at 09:10AM PDT, ID: 20770238
[x]
Attachment Details

Adding parameters to an ADO Command

Asked by MrKevorkian in Visual Basic Programming

Tags: ,

is there a way to append parameters to a command in a loop.  In a way that you dont have to specify:

- the parameter name
- the datatype
- the parameter type
- the size of the parameter
- the value going into the parameter

as hardcoded items - rather can you use variables to set these

what i was thinking was using an Generic function like this:

'************************************************

Public Sub ExecuteParameter(sStoredProcedure As String, _
                                           arrParameters() As String)


Dim iCounter As Integer
dim objSQLCommand as ADODB.command

Set objSQLCommand = New ADODB.Command
objSQLCommand.ActiveConnection = objSQLConnection
objSQLCommand.CommandType = adCmdStoredProc
objSQLCommand.CommandText = sStoredProcedure

    For iCounter = 0 To UBound(arrParameters(), 2)

    objSQLCommand.Parameters.Append _
    objSQLCommand.CreateParameter(arrParameters(0, iCounter), _
                               arrParameters(1, iCounter), _
                               arrParameters(2, iCounter), _
                               arrParameters(3, iCounter), _
                               arrParameters(4, iCounter))

    Next iCounter

objSQLCommand.Execute

Set objSQLCommand = Nothing

End Sub

'************************************************

The problem is it seems that when you say

objSQLParameter.createparameter  - the arguments that follow must be Hardcoded - so i cannot just use an array to hold the values.

Is there a way around this?

thanks

Start Free Trial
 
Loading Advertisement...
 
[+][-]10.17.2003 at 10:37AM PDT, ID: 9573083

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.17.2003 at 10:40AM PDT, ID: 9573106

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Tags: parameter, command
Sign Up Now!
Solution Provided By: cero
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.21.2003 at 07:12AM PDT, ID: 9590870

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2004 at 01:45PM PDT, ID: 10778479

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32