Home All Groups Group Topic Archive Search About

Is it possibly to specify store procedure parameters by position instead by name?

Author
16 Jan 2006 6:46 PM
SammyBar
Hi,

I'm developing a new .NET application but using the same stored procedures
(Sql Server 2000) that are in use by an old client server application. The
problem is that it is common when refactoring stored procedures, to change
the name of the parameters. It was not a problem since the old application
uses ODBC and the parameters are called by position, not by name. But
ADO.NET requires to me to specify parameters by name
parm = cmd.Parameters.Add("@ParamName", SqlDbType.Int);

Then when the sp get revised and updated to our new coding standard
(@ParamName will be renamed to @nParamName) it will break my code.

Is it any way I can specify the parameters by position, something like:

parm = cmd.Parameters.Add(0, SqlDbType.Int);

Any hint is welcomed.

Thanks in advance

Sammy

Author
16 Jan 2006 8:39 PM
William (Bill) Vaughn
Not really unless you roll the EXEC mySP parm,parm2 line yourself.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
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.
__________________________________

Show quote
"SammyBar" <sammy***@gmail.com> wrote in message
news:eXpm1zsGGHA.1032@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I'm developing a new .NET application but using the same stored procedures
> (Sql Server 2000) that are in use by an old client server application. The
> problem is that it is common when refactoring stored procedures, to change
> the name of the parameters. It was not a problem since the old application
> uses ODBC and the parameters are called by position, not by name. But
> ADO.NET requires to me to specify parameters by name
> parm = cmd.Parameters.Add("@ParamName", SqlDbType.Int);
>
> Then when the sp get revised and updated to our new coding standard
> (@ParamName will be renamed to @nParamName) it will break my code.
>
> Is it any way I can specify the parameters by position, something like:
>
> parm = cmd.Parameters.Add(0, SqlDbType.Int);
>
> Any hint is welcomed.
>
> Thanks in advance
>
> Sammy
>
>
Author
17 Jan 2006 12:39 AM
Robbe Morris [C# MVP]
This is one reason I use my code generator.

http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





Show quote
"SammyBar" <sammy***@gmail.com> wrote in message
news:eXpm1zsGGHA.1032@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I'm developing a new .NET application but using the same stored procedures
> (Sql Server 2000) that are in use by an old client server application. The
> problem is that it is common when refactoring stored procedures, to change
> the name of the parameters. It was not a problem since the old application
> uses ODBC and the parameters are called by position, not by name. But
> ADO.NET requires to me to specify parameters by name
> parm = cmd.Parameters.Add("@ParamName", SqlDbType.Int);
>
> Then when the sp get revised and updated to our new coding standard
> (@ParamName will be renamed to @nParamName) it will break my code.
>
> Is it any way I can specify the parameters by position, something like:
>
> parm = cmd.Parameters.Add(0, SqlDbType.Int);
>
> Any hint is welcomed.
>
> Thanks in advance
>
> Sammy
>
>

AddThis Social Bookmark Button