Updating SP Parameter values

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
 
W

William Ryan

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
 
C

Chuck D

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
 

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