Object reference not set to an instance of an object

P

pj

Can anyone help? I getting this error on line 17:

Object reference not set to an instance of an object.

Line 15: Dim UserGUID As Object = User.ProviderUserKey
Line 16:
Line 17: DataSource.InsertParameters.Add("UserID",
UserGUID.ToString())
Line 18: DataSource.Insert()

Here's my code:

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object,
ByVal e As System.EventArgs)

Dim UserNameTextBox As TextBox =
CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"),
TextBox)
Dim DataSource As SqlDataSource =
CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"),
SqlDataSource)

Dim User As MembershipUser =
Membership.GetUser(UserNameTextBox.Text)
Dim UserGUID As Object = User.ProviderUserKey

DataSource.InsertParameters.Add("UserID", UserGUID.ToString())
DataSource.Insert()

End Sub
 
T

Tim_Mac

hi pj,
you are calling a method on a null object, hence the Null reference
exception. User.ProviderUserKey is null, so you can't call .ToString() on
it.
there must be something you are not initialising correctly with the user
object. i suggest you read the SDK pages for this class to see how to set
it up correctly.

tim
 
R

Rob MacFadyen

pj,

The User variable likely has the value null. If the specified userid is not
known then Membership.GetUser(string) will return null.

Regards,

Rob MacFadyen
 
Joined
May 13, 2008
Messages
1
Reaction score
0
can you help please

Hi, PJ,

I have same issue as yours. I spent almost two days and tried what I can think of, but still cannot figure out.
But one step progress is that something wrong with sqldatasource.
You said you didn't initiate the sqldatasource, what do you mean?
can you tell me where you changed the code?
I'm using the same example from 4guys website to use the customized createuserwizard.

Thank you!
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,043
Members
48,769
Latest member
Clifft

Latest Threads

Top