Insert session values in database table ASP.NET (VB)

I am assigning a session value to a text box. I know the session value is there because I can read it when I have the textbox value set to Visible. I am using a Stored Proc to insert three values as you see in my code. I am not quite able to get the syntax correct in the code behind. When I press the submit button and attempt the insert I receive the following error. I know I am close but I need some help with the syntax:

***Procedure or function 'search_static' expects parameter '@SessionNames', which was not supplied.

My Code below

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Session("SessionNames") = Session.SessionID


    End Sub

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ImageButton1.Click

        Dim strConnString As String = ConfigurationManager.ConnectionStrings("SQL2008R2_504887_golivefitnesConnectionString").ConnectionString
        Dim con As New SqlConnection(strConnString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Search_static"
        cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = search.Text.Trim()
        cmd.Parameters.Add("@SessionName", SqlDbType.VarChar).Value = SessionNames.ToString()
        cmd.Parameters.Add("@qtrname", SqlDbType.VarChar).Value = search.Text.Trim()

        cmd.Connection = con
            'lblMessage.Text = "Record inserted successfully"
        Catch ex As Exception
            Throw ex
        End Try

    End Sub
derrekdeveloperEnterprise Solution ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel Van Der WerkenIndependent ConsultantCommented:
Looks to me like the stored procedure is expecting the parameter @SessionNames. You are passing in @SessionName (minus the final "s").

Try passing in @SessionNames instead of@SessionName.
cmd.Parameters.Add("@SessionNames", SqlDbType.VarChar).Value = SessionNames.ToString()

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
or try:

cmd.Parameters.Add("@SessionName", SqlDbType.VarChar).Value = Session("SessionNames") .ToString()


What's the object type for SessionNames?
derrekdeveloperEnterprise Solution ArchitectAuthor Commented:
Both answers provided exactly what I needed. Management has dulled my technical skills.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.