PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Create User Wizard Insert Issue

 
 
sjsean
Guest
Posts: n/a
 
      17th May 2010
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.
 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      25th May 2010
On May 17, 8:27*am, sjsean <sjsean95...@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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TableAdapter Configuration Wizard do not create Insert Statement M Microsoft VB .NET 0 19th Jul 2007 04:07 PM
create user wizard Jon Paal Microsoft ASP .NET 1 18th Jan 2007 07:32 AM
Create user wizard issue Amir Ghezelbash Microsoft ASP .NET 0 9th Mar 2006 02:38 AM
2.0 Create User Wizard! Adam J Knight Microsoft ASP .NET 0 17th Dec 2005 08:21 AM
Insert Function wizard for User Defined Functions =?Utf-8?B?TkJD?= Microsoft Excel Programming 2 14th Mar 2005 07:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:34 AM.