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 =
    LastName)

    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
    CreateUserWizard1.CreatedUser
    If Not Page.IsValid Then Exit Sub

    ' Determine the currently logged on user's UserId
    Dim newUser As MembershipUser =
    Membership.GetUser(CreateUserWizard1.UserName)
    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 =

    ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString
    Dim insertSql As String = "INSERT INTO
    aspnet_UserDetails(Userid, FirstName, LastName) VALUES(@UserId,
    @FirstName, @LastName)"

    Using myConnection As New SqlConnection(connectionString)
    myConnection.Open()
    Dim myCommand As New SqlCommand(insertSql, myConnection)
    myCommand.Parameters.AddWithValue("@UserId", newUserId)
    myCommand.Parameters.AddWithValue("@FirstName",
    FirstName.Text.Trim())
    myCommand.Parameters.AddWithValue("@LastName",
    LastName.Text.Trim())
    myCommand.ExecuteNonQuery()
    myConnection.Close()
    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
    1. Advertising

  2. On May 17, 8:27 am, sjsean <> wrote:
    > 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.
    >


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

    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
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    3
    Views:
    2,883
    Joshua Flanagan
    Dec 11, 2005
  2. John

    Customizing create user wizard

    John, Dec 14, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    10,723
    Joshua Flanagan
    Dec 15, 2005
  3. Amir Ghezelbash

    Create user wizard issue

    Amir Ghezelbash, Mar 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    424
    Amir Ghezelbash
    Mar 9, 2006
  4. Replies:
    0
    Views:
    613
  5. Andy B
    Replies:
    0
    Views:
    447
    Andy B
    Apr 19, 2008
Loading...

Share This Page