Passing Parameters?

W

Walter Enzor

I have been looking into Microsoft's Data Access
Application Block, and it has a procedure for calling a
stored procedure that only returns parameters and no
recordset. I would like to use this, but it accepts
parameters as a ParamArray, which, to the best of my
knowledge, can only be referenced by number. If I have a
large number of parameters, I'd like to be able to
reference them by name to improve the understandability
of my code. Does anyone have any ideas on what is the
best way to pass parameters to a procedure so I can
reference the returned parameter values by name? I still
need the procedure to be generic so I can pass any number
of parameters to it.

Thanks for any insight,

Walter Enzor
Elliott Wave International
 
W

William \(Bill\) Vaughn

Perhaps a home-grown (you code it) enumeration would help.

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
W

Walter Enzor

Hmmm...that's not a bad idea. I worked on a small
function that searches the array, and since the arrays
aren't going to be huge, I don't believe it will be too
much of a performance penalty. It certainly seems fast
from my tests. Here's what I came up with:

Public Shared Function SearchParamArray(ByVal
ParameterName As String, ByVal ParamArray
commandParameters() As SqlParameter) As SqlParameter
Dim myEnumerator As
System.Collections.IEnumerator =
commandParameters.GetEnumerator()
Dim i As Integer = 0
Dim sqlParam As SqlParameter

While myEnumerator.MoveNext()
sqlParam = myEnumerator.Current()
If sqlParam.ParameterName = ParameterName Then
Return sqlParam
End If
End While

End Function

And consequently, this would replace the last line of my
code example from my previous post:
Me.lblEntityID2.Text = SearchParamArray("@EntityID",
arParms).Value

While I'm not a big fan of making this call, it does have
the benefit of not having to keep my enumeration and
parameter list in sync if a change is made. Do you (or
anyone else) see any down-side to this as a solution?

Thanks again,

Walter Enzor
 
W

William \(Bill\) Vaughn

What I meant was
Enum Tires
Goodyear
Firestone
Toyo
End Enum

if mytires(Tires.GoodYear) = ...




--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top