Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 780
  • Last Modified:

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

I'm still fairly new to asp.net 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

        Try
            conn.Open()
            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

            cmd.ExecuteNonQuery()

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

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

Can anyone tell me what i'm doing wrong?

Thanks
0
kpbarem
Asked:
kpbarem
1 Solution
 
CodeCruiserCommented:
Change this

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

to

cmd.CommandText = "dbo.enterRespondents"
0
 
kpbaremAuthor Commented:
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now