Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
An SqlParameter with ParameterName '@Id' is not contained by this SqlParameterCollection. 


this is my error ....

What I have tried:

VB
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cmmd As New SqlCommand
        For i = 0 To GridView1.Rows.Count - 1
            If CType(GridView1.Rows(i).FindControl("CheckBox1"), CheckBox).Checked Then
                cmmd.Parameters("@Id").Value = CType(GridView1.Rows(i).FindControl("TxtId"), TextBox).Text
                cmmd.Parameters("@Setup_Type").Value = CType(GridView1.Rows(i).FindControl("TxtType"), TextBox).Text
                cmmd.Parameters("@Setup_name").Value = CType(GridView1.Rows(i).FindControl("TxtName"), TextBox).Text
                Exit Sub
            Else
                cmmd.Parameters("@Id").Value = ""
                cmmd.Parameters("@Setup_Type").Value = ""
                cmmd.Parameters("@Setup_name").Value = ""
            End If
        Next
    End Sub
Posted
Updated 17-Mar-16 4:40am
v2

1 solution

You need to add the parameters to cmmd before attempting to set the Value
e.g.
VB
cmmd.Parameters.AddWithValue("@Id", CType(GridView1.Rows(i).FindControl("TxtId"), TextBox).Text)
 
Share this answer
 
Comments
Malak Hudaib 20-Mar-16 7:23am    
thx ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900