Updating SP Parameter values

  • Thread starter Thread starter Chuck D
  • Start date Start date
C

Chuck D

Folks,

Can I update the value of a paramater used by a command AFTER adding the
paramater to the command, and then update it to a new value?

I want to loop through a set of values, and call a SP several times varying
one of the paramaters each time. I had hoped to do something like this bit
of psudocode;

SqlCommand myCommand = new SqlCommand("SPname", myConnection);

myCommand.CommandType = CommandType.StoredProcedure;

SqlParameter parameterProductID = new SqlParameter("@ProductID",
SqlDbType.Int, 4);

myCommand.Parameters.Add(parameterProductID);

myConnection.Open();

while (varying <n>)

{
parameterProductID.Value = productID(n);
myCommand.ExecuteNonQuery();

}

myConnection.Close()

Does this look kosher?

Chuck
 
Yes, you can just add the parameter without adding the value. Then you can
add to it and change it all you want. Justmake sure you always add
something to it, and make sure you don't add a second instance of it.

Cheers,

Bill
 
Thanks Bill. I'll give it a whirl.

cd
William Ryan said:
Yes, you can just add the parameter without adding the value. Then you can
add to it and change it all you want. Justmake sure you always add
something to it, and make sure you don't add a second instance of it.

Cheers,

Bill
 
Back
Top