Kirk Evans Blog

.NET From a Markup Perspective

Set Parameter Values, Don’t Just .Clear Them

Okay, this bit of code iterates through a loop, running a stored procedure for each pass. The only item that differs from the normal use of a stored procedure is the line that reads objComm.Parameters.Clear(). Without this line, the parameters would continue to be added and not reset as they should be.[Scott Stoecker Blog]

Why would you .Clear the parameters? Wouldn’t you simply set the new value of the existing parameter objects?

objComm.Parameters(“strOne”).Value = “new value 1”
objComm.Parameters(“strTwo”).Value = “new value 2”

Another tip is to use the .Prepare method when accessing a resource that supports it.