Error: A SQLParamenter wtih ParameterName @myparm is not contained by this SQLParameter Collection
- by SidC
Good Morning,
I'm working on an ASP.NET 3.5 webforms application and have written the following code:
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim connectionString As String = WebConfigurationManager.ConnectionStrings("Diel_inventoryConnectionString").ConnectionString
Dim con As New SqlConnection(connectionString)
Dim adapter1 As New SqlDataAdapter
adapter1.SelectCommand = New SqlCommand
adapter1.SelectCommand.CommandType = CommandType.StoredProcedure
adapter1.SelectCommand.CommandText = "PartSproc"
Dim parmNSN As New SqlParameter("@NSN", SqlDbType.NVarChar)
Dim parmName As New SqlParameter("@PartName", SqlDbType.NVarChar)
txtNSN.Text = adapter1.SelectCommand.Parameters("@NSN").Value
txtSearch.Text = adapter1.SelectCommand.Parameters("@PartName").Value
Dim dt As New DataTable()
adapter1.Fill(dt)
MySearch.DataSource = dt
MySearch.DataBind()
End Sub
When I run the page, I receive the error A SQLParameter with @NSN is not contained by this SQLParameter Collection. I tried using apostrophes around the @NSN and @PartName but that does not work either and presents expression expected error.
How might I rectify the above code so that it references the @NSN and @PartName parameters correctly?
Thanks,
Sid