Error: A SQLParamenter wtih ParameterName @myparm is not contained by this SQLParameter Collection

Posted by SidC on Stack Overflow See other posts from Stack Overflow or by SidC
Published on 2010-03-17T13:35:13Z Indexed on 2010/03/17 13:51 UTC
Read the original article Hit count: 282

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

© Stack Overflow or respective owner

Related posts about asp.net-3.5

Related posts about sql-server-2005