From: sjsean on
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.
From: Alexey Smirnov on
On May 17, 8:27 am, sjsean <sjsean95...(a)gmail.com> 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