Saturday, March 24, 2012

Object reference not set to an instance of an object

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.ContentTemplateContain er.FindControl("UserName"),
TextBox)
Dim DataSource As SqlDataSource =
CType(CreateUserWizardStep1.ContentTemplateContain er.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........i got it....my datasource wasn't being initiated...duh!

pj, mcdba, mcp
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

"pj" <pjtort@.yahoo.comwrote in message
news:1158181026.939664.147470@.e63g2000cwd.googlegr oups.com...

Quote:

Originally Posted by

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.ContentTemplateContain er.FindControl("UserName"),
TextBox)
Dim DataSource As SqlDataSource =
CType(CreateUserWizardStep1.ContentTemplateContain er.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
>


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

"pj" <pjtort@.yahoo.comwrote in message
news:1158181026.939664.147470@.e63g2000cwd.googlegr oups.com...

Quote:

Originally Posted by

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.ContentTemplateContain er.FindControl("UserName"),
TextBox)
Dim DataSource As SqlDataSource =
CType(CreateUserWizardStep1.ContentTemplateContain er.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
>

0 comments:

Post a Comment