By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,589 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,589 IT Pros & Developers. It's quick & easy.

Object reference not set to an instance of an object

P: n/a
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.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

Sep 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
pj
..........i got it.....my datasource wasn't being initiated....duh!

pj, mcdba, mcp

Sep 13 '06 #2

P: n/a
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" <pj****@yahoo.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...
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

Sep 13 '06 #3

P: n/a
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" <pj****@yahoo.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...
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

Sep 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.