Create User Wizard Insert Issue

Discussion in 'ASP .Net' started by sjsean, May 17, 2010.

  1. sjsean

    sjsean Guest

    I have placed a create user wizard on a page and added two textbox
    fields in addition for First name (id = FirstName) and Last Name (id =

    However when I try to insert all the information into my created table
    all I get is errors. I've tried for hours to understand various web
    examples and just am missing something. Below is my vb code on my
    code behind page. I keep getting "NullReferenceException was
    unhandled by user code"

    My database table does not accept nulls for First or Last names. But
    since these values have always been provided when "testing" something
    else must be happening.

    Imports System.Data.SqlClient
    Imports System.Web.UI.Control

    Partial Class register
    Inherits System.Web.UI.Page

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles
    If Not Page.IsValid Then Exit Sub

    ' Determine the currently logged on user's UserId
    Dim newUser As MembershipUser =
    Dim newUserId As Guid = CType(newUser.ProviderUserKey, Guid)

    Dim FirstName As TextBox =
    CType(CreateUserWizard1.FindControl("FirstName"), TextBox)
    Dim LastName As TextBox =
    CType(CreateUserWizard1.FindControl("LastName"), TextBox)

    Dim connectionString As String =

    Dim insertSql As String = "INSERT INTO
    aspnet_UserDetails(Userid, FirstName, LastName) VALUES(@UserId,
    @FirstName, @LastName)"

    Using myConnection As New SqlConnection(connectionString)
    Dim myCommand As New SqlCommand(insertSql, myConnection)
    myCommand.Parameters.AddWithValue("@UserId", newUserId)
    End Using

    End Sub

    I am guessing possibly that I am not gathering the information from
    the text boxes correctly by the code above. If so can someone advise
    what that code might be using plain english and an example so I may
    better understand.

    Thanks in advance.
    sjsean, May 17, 2010
    1. Advertisements

  2. Just do a little test to be sure that this is not because of anything

    Get rid of your code and simply do

    Dim FirstName As TextBox =
    CType(CreateUserWizard1.FindControl("FirstName"), TextBox)

    to see if the TextBox was found on the page
    Alexey Smirnov, May 25, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.