Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Run a procedure without specifying a parameter name

How can I execute a stored procedure that takes in parameters without having to specify the prameters name? The name of the parameter in the stored procedure may change from CustomerID to CustID so I don't want to have to keep changing my code.

Rather than doing what is provided below where you specify the parameter name -

command.Parameters.Add("@dtStart", SqlDbType.DateTime);
command.Parameters["@dtStart"].Value = startDate;
command.Parameters.Add("@CustomerID", SqlDbType.NChar);
command.Parameters["@CustomerID"].Value = customerID;

I am looking to do something like this -

command.Parameters.Add(startDate, customerID);
like image 510
m0g Avatar asked Mar 03 '11 14:03

m0g


1 Answers

The name of the parameter in the stored procedure may change from CustomerID to CustID

Slap the person who does that.

Parameter names are your reliable way of identifying a parameter. The other option is sequence, seems a lot more flaky.

like image 54
Henk Holterman Avatar answered Oct 30 '22 18:10

Henk Holterman