Running a stored procedure in a loop. My two picks for the NCAA Finals came true. Let's see if Kansas wins tonight.
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.
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click ‘Db declarations and such
For i = intFirst To intLast objParam = objComm.Parameters.Add("ID", OleDbType.Numeric, 7) objParam.Direction = ParameterDirection.Input objParam.Value = Session("ID")
objParam = objComm.Parameters.Add("strOne", OleDbType.Numeric, 7) objParam.Direction = ParameterDirection.Input objParam.Value = strOne
objParam = objComm.Parameters.Add("strTwo", OleDbType.Numeric, 7) objParam.Direction = ParameterDirection.Input objParam.Value = strTwo
objComm.ExecuteScalar() objComm.Parameters.Clear()
End If Next End Sub [.NET Weblogs]
Very good trick to remember!
11:52:39 AM - See Also: .NET
|