Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An SqlParameter with ParameterName '@Guid ' is not contained by this SqlParameterCollection.

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Not sure what I am doing wrong here because I thought I was adding the parameter Guid to the collection?

Code:
Protected Sub btnRegister_Click(sender As Object, e As System.EventArgs) Handles btnRegister.Click

        Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("xforafricaConnectionString").ConnectionString
        Dim con As New SqlConnection(ConnString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "AddNewRegistration"
        cmd.Parameters.Add("@Firstname", SqlDbType.VarChar).Value = txtFirstname.Text.Trim()
        cmd.Parameters.Add("@Surname", SqlDbType.VarChar).Value = txtSurname.Text.Trim()
        cmd.Parameters.Add("@Company", SqlDbType.VarChar).Value = txtCompany.Text.Trim()
        cmd.Parameters.Add("@EmailAddress", SqlDbType.NVarChar).Value = txtEmail.Text.Trim()
        cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = txtPassword.Text.Trim()
        cmd.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier).Direction = ParameterDirection.Output



        cmd.Connection = con


        Try
            con.Open()
            cmd.ExecuteScalar()


            Dim Guid As String
            Guid = DirectCast(cmd.Parameters("@Guid ").Value, String)

            Response.Write(Guid)

        Catch ex As Exception
            Throw ex
        Finally
            con.Close()
            con.Dispose()
        End Try





      
        'send_email()
        'RegForm.Visible = False
        ' RegSuccess.Visible = True
        ' Response.AddHeader("Refresh", "3;URL=index.aspx")
    End Sub
 
You have a space after the word @Guid:
Code:
 Guid = DirectCast(cmd.Parameters("@Guid ").Value, String)

Change cmd.Parameters("@Guid ")
To
cmd.Parameters("@Guid")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top