How to execute a stored procedure in VB Code Behind file?

Posted on 2012-08-11
Last Modified: 2012-08-11
I'm still fairly new to and i'm trying to execute a simple stored procedure to insert information into a database.

Here is the code that I have that is not working:

        Dim sconn As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim conn As New SqlConnection(sconn)
        Dim cmd As New SqlCommand

            cmd.Connection = conn
            cmd.CommandText = "Execute dbo.enterRespondents @firstName, @lastName, @email @comment"
            cmd.Parameters.AddWithValue("@firstName", Txt_FirstName.Text)
            cmd.Parameters.AddWithValue("@lastName", Txt_LastName.Text)
            cmd.Parameters.AddWithValue("@email", Txt_EmailAddress.Text)
            cmd.Parameters.AddWithValue("@comment", Txt_Comment.Text)
            cmd.CommandType = Data.CommandType.StoredProcedure


The error i'm getting is that it is unable to find this procedure.  I'm not sure if this is a problem with the code or a problem with sql server express since i've also never worked with that before.  

Here is my connection string to sql server express

            <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Respondents.mdf;Integrated Security=True;User Instance=True"
            providerName="System.Data.SqlClient" />

Can anyone tell me what i'm doing wrong?

Question by:kpbarem
    LVL 83

    Accepted Solution

    Change this

    cmd.CommandText = "Execute dbo.enterRespondents @firstName, @lastName, @email @comment"


    cmd.CommandText = "dbo.enterRespondents"

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now