Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 679767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:17:48+00:00 2026-05-14T01:17:48+00:00

Good Morning, I’m working on an ASP.NET 3.5 webforms application and have written the

  • 0

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?

EDIT: New Code below

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 cmd As New SqlCommand("PartSproc", con)
    cmd.CommandType = CommandType.StoredProcedure
    Dim adapter1 As New SqlDataAdapter

    Dim parmNSN As New SqlParameter("@NSN", SqlDbType.NVarChar)
    Dim parmName As New SqlParameter("@PartName", SqlDbType.NVarChar)
    adapter1.SelectCommand.Parameters.Add(parmNSN)
    adapter1.SelectCommand.Parameters.Add(parmName)
    adapter1.SelectCommand.Parameters("@NSN").Value = txtNSN.Text
    adapter1.SelectCommand.Parameters("@PartName").Value = txtSearch.Text
    Using con
        Dim dt As New DataTable()
        adapter1.SelectCommand = cmd
        adapter1.Fill(dt)
        MySearch.DataSource = dt
        MySearch.DataBind()
    End Using
End Sub

I now receive an error Object reference not set to an instance of an object referencing the add parameter parmNSN. Do I really need those to add paraameter statements since I’ve already set them equal to the text boxes below?

Thanks,
Sid

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:17:49+00:00Added an answer on May 14, 2026 at 1:17 am

    I think you accidentally transposed the assignment of the parameter values – try this instead:

    adapter1.SelectCommand.Parameters("@NSN").Value = txtNSN.Text
    adapter1.SelectCommand.Parameters("@PartName").Value = txtSearch.Text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning All, I am developing a new ASP.net MVC web application. Part of
Good Morning, Has anyone attempted to convert/migrate an ASP.net MVC web application project to
Good Morning, I've written the following stored procedure that searches for records that have
Good Morning, I have a very odd error working in adobe flexbuilder 3. Ever
Good morning. I have the next code which put some markers in a map
Good Morning, I have copied this code from somewere <script type=text/javascript> $(function() { setInterval(rotateImages(),
Good Morning/Afternoon all, I have a ASP:grid which displays current versions of Terms and
good morning programers, I have this small code which content a news control panel
Good morning, I have a .Net 2.0 runtime DLL that I am trying to
Good Morning, I have an application which allows users to slide values for different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.