Parameters.Add() loop [RESOLVED]
Here's what I've got so far:
I'm creating two parameters in a loop and filling them with a variable. Then after running my ExecuteNonQuery I emtpy the parameters with Parameters.Remove() and start the loop again, filling the parameters with new values, and executing.
Now when I only loop once, it works fine. If the loop occurs more than once, and the Parameters.Remove() takes effect, I get an error:
The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects.
If I comment out my Parameters.Remove() lines, and only loop once, it works fine. Am I using the correct property of Parameter.Remove() to emtpy or remove these parameters? Like I said, everything works perfectly if I only loop once with one set of values for the Parameters and comment out Parameters.Remove(). It seems to me that its not removing the Parameter correctly and starting the loop over, and adding them again.
Here's my code:
VB Code:
Dim sTeamLeaderID, sCounselorID As Integer
Dim sqlConn As New SqlClient.SqlConnection("server=(local); uid=sa; pwd=;initial catalog=IFPAWEB")
Dim sqlSPteam As New SqlClient.SqlCommand("sp_teamleadercounselor", sqlconn)
Dim i As Integer
sTeamLeaderID = CounselorsTeamLeaderName.Value
Try
sqlConn.Open()
For i = 0 To CounselorsCounselors.Items.Count - 1
If CounselorsCounselors.Items(i).Selected Then
sCounselorID = CounselorsCounselors.Items(i).Value
With sqlSPteam
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@counselorid", Convert.ToInt32(sCounselorID))
.Parameters.Add("@teamleaderid", sTeamLeaderId)
.ExecuteNonQuery()
.Parameters.Remove("@counselorID")
.Parameters.Remove("@teamleaderid")
End With
End If
Next i
Finally
SqlConn.Close()
End Try
Thanks!!