drpcken
Posts: 60
|
Posted: 08/23/2004, 8:44 AM |
|
I created a loop that goes through a listbox, and grabs the selected value if its selected, stores it in a parameter, then runs a stored procedure in sql, then does the same thing for the next selected item in the listbox. However I get the error "The SqlParameter Collection only accepts non-null SqlParameter type objects, not String object" every time. It does however insert the first selected record, but seems to error out when it loops again. I can't figure this out for the life of me. Here's my vb code:
Dim sTeamLeaderID, sCounselorID As String
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
Try
sqlConn.Open()
Finally
For i = 0 To CounselorsCounselors.Items.Count - 1
If CounselorsCounselors.Items(i).Selected Then
sTeamLeaderID = CounselorsTeamLeaderName.Value
sCounselorID = CounselorsCounselors.Items(i).Value.ToString
With sqlSPteam
.Connection = sqlConn
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@counselorid", convert.ToInt32(sCounselorid))
.Parameters.Add("@teamleaderid", convert.ToInt32(steamleaderID))
.ExecuteNonQuery()
.Parameters.Remove("@counselorID")
.Parameters.remove("@teamleaderid")
End With
End If
Next i
SqlConn.Close()
End Try
and here is my stored procedure:
CREATE proc sp_teamleadercounselor
@counselorid int,
@teamleaderid int
as
declare @date1 datetime
set @date1=getdate()
--delete teamleadercounselor where teamleaderid=@teamleaderid
insert into teamleadercounselor (teamleaderid,counselorid,modify_date)
values (@teamleaderid,@counselorid,@date1)
GO
Thanks!!!
|