Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO command.parameters by name NOT position

Status
Not open for further replies.

EdMacDonald

Programmer
Apr 13, 2000
20
CA
Is there a way to call a stored proc and reference the parameters by name instead of by position?<br>------<br>I am using the following syntax to add parameters to a command object that executes a SQL 7 stored proc:<br>&nbsp;&nbsp;&nbsp;<FONT FACE=monospace>cmd.Parameters.Append cmd.CreateParameter(&quot;@p1&quot;, adVarChar, adParamInput, 50)</font><br>I would like to have the parameters passed by name instead of by position.&nbsp;&nbsp;Is there a way to do this within ADO?<br><br>Thanks,<br><br>Ed<br><br><br><br>
 
&nbsp;&nbsp;&nbsp;With the example above use:<br><br>&nbsp;&nbsp;&nbsp;cmd.CreateParameter(&quot;@p1&quot;, adVarChar, adParamInput, 50)<br>&nbsp;&nbsp;&nbsp;'uses the default name<br>&nbsp;&nbsp;&nbsp;cmd.Parameters.Append&nbsp;&nbsp;cmd.parameters (&quot;p1&quot;)<br><br>&nbsp;&nbsp;&nbsp;or even this:<br><br>&nbsp;&nbsp;&nbsp;cmd.CreateParameter(&quot;@p1&quot;, adVarChar, adParamInput, 50)<br>&nbsp;&nbsp;&nbsp;'change the default name<br>&nbsp;&nbsp;&nbsp;cmd.parameters(0).Name = &quot;Parameter1&quot;<br>&nbsp;&nbsp;&nbsp;cmd.Parameters.Append&nbsp;&nbsp;cmd.Parameters (&quot;Parameter1&quot;)<br><br><font color=red>Careful with this guy; unique names are not required for parameter names.</font><br>&nbsp;<br><br><br> <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
What I really want to do is the equivalent of:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE=monospace>execute myStoredProc @p2='val2', @p1='val1'</font><br>or<br>&nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE=monospace>myVBfunction p1:='val1', p2:='val2'</font><br><br>When working with a DB person, I'd rather agree on the parameter names than their position in the declaration.<br><br>Thanks,<br><br>Ed<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top