Solved

membership insert

Posted on 2009-06-30
6
461 Views
Last Modified: 2012-05-07
Good day experts. I search high and low and none of these blogs really help I keep getting an error saying
Object reference not set to an instance of an object

I just want to insert data and copy the user key into my new table. thats it. why does it has to be so difficult.
Just some one show me or tell me what am i doing wrong. This is driving me nuts for 2 days.

''######################################################
<asp:CreateUserWizard ID="CreateUserWizard1"          
                 runat="server"  
        CreateUserButtonText="Submit">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
                <ContentTemplate>
                <table><tr><td align="left">
<div align="left">
<table border="0">
<tbody align="left">
<tr>
<td align="left" colspan="2">
<asp:Label ID=top runat=server Text="Sign Up for Your New Account" Font-Bold="True" Font-Size="10pt"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label1" runat="server" >First Name:</asp:Label></td>
<td align=left>
<asp:TextBox ID="fname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label2" runat="server" >Last Name:</asp:Label></td>
<td align=left>
<asp:TextBox ID="lname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label4" runat="server" >Company:</asp:Label></td>
<td align=left>
<asp:TextBox ID="Company" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label5" runat="server" >StreetAddress:</asp:Label></td>
<td align=left>
<asp:TextBox ID="address1" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label6" runat="server" >City:</asp:Label></td>
<td align=left>
<asp:TextBox ID="city" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label7" runat="server" >State:</asp:Label></td>
<td align=left>
    <asp:DropDownList ID="state" runat="server" AppendDataBoundItems="False" DataTextField="state"   DataSourceID="GetQuestion" Visible="true"  Height="20px" Width="124px">
                                    </asp:DropDownList>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label8" runat="server" >ZipCode:</asp:Label></td>
<td align=left>
<asp:TextBox ID="zip" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td align="right" class="style1">
<asp:Label ID="Label10" runat="server" >Phone:</asp:Label></td>
<td align=left>
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label11" runat="server" >Fax:</asp:Label></td>
<td align=left>
<asp:TextBox ID="Fax" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td align="right" class="style1">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Log in Email Address:</asp:Label></td>
<td align=left>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Create Password:</asp:Label></td>
<td align=left>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label></td>
<td align=left>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
ValidationGroup="CreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="EmailLabel" runat="server" Visible="false" AssociatedControlID="Email">E-mail:</asp:Label></td>
<td align=left>
<asp:TextBox ID="Email" Visible="true" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUser">*</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td align="center" colspan=2>
<div align="center"><font FACE="Arial, Helvetica, Sans" SIZE="3" color="#FF0000">Type the letters seen in the image below:</font></div>
 <div align="center"><b>Verification:</b></div>
 <div align="center">
     <asp:TextBox ID="CaptchaTxt" runat="server"  ></asp:TextBox></div>
   <cc1:captchacontrol id="CaptchaControl1"  CustomValidatorErrorMessage="*Please retry to confirm you are human." runat="server" FontColor="80, 35, 114"
        CaptchaFontWarping="Medium" CaptchaBackgroundNoise="Medium"></cc1:captchacontrol>

   

</td>
</tr>

<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUser"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: red">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</tbody>
</table>
</div>
 </td></tr></table>
     <%--<asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:TakeNoteConnectionString %>" InsertCommand="INSERT INTO Users(UserID,Username,Password,fname,lname,address1,city,state,zip) VALUES (@UserID,@Username,@Password,@fname,@lname,@address1,@city,@state,@zip)" ProviderName="System.Data.SqlClient">
           <InsertParameters>
               <asp:ControlParameter ControlID="Username" Name="Username" PropertyName="Text" />
               <asp:ControlParameter ControlID="Password" Name="Password" PropertyName="Text" />
                <asp:ControlParameter ControlID="ConfirmPassword" Name="Password" PropertyName="Text" />
              <asp:ControlParameter ControlID="fname" Name="fname" PropertyName="Text" />
               <asp:ControlParameter ControlID="lname" Name="lname" PropertyName="Text" />
              <asp:ControlParameter ControlID="address1" Name="address1" PropertyName="Text" />
              <asp:ControlParameter ControlID="address2" Name="address2" PropertyName="Text" />
               <asp:ControlParameter ControlID="city" Name="city" PropertyName="Text" />
               <asp:ControlParameter ControlID="state" Name="state" PropertyName="Text" />
               <asp:ControlParameter ControlID="zip" Name="zip" PropertyName="Text" />
           </InsertParameters>
        </asp:SqlDataSource>--%>
       
 
</ContentTemplate>
            </asp:CreateUserWizardStep>
          <%--  <asp:CompleteWizardStep ID="CompleteWizardStep2" runat="server">
            <ContentTemplate>      
           
            </ContentTemplate>
            </asp:CompleteWizardStep>--%>
        </WizardSteps>
    </asp:CreateUserWizard>  


''#######################################################
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser

        ' Get the UserId of the just-added user

        Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
 

        If Not user Is Nothing Then

            Dim userId As New Guid(user.ProviderUserKey.ToString())
 

            Dim fname As TextBox = CType(CreateUserWizard1.FindControl("fname"), TextBox)

            Dim lname As TextBox = CType(CreateUserWizard1.FindControl("lname"), TextBox)

            Dim address1 As TextBox = CType(CreateUserWizard1.FindControl("address1"), TextBox)
 

            ' Update the UserProfiles record for this user

            ' Get the UserId of the just-added user

            '  Dim newUserId As Guid = CType(newUser.ProviderUserKey, Guid)
 

            ' Insert a new record into UserProfiles

            Dim connectionString As String = ConfigurationManager.ConnectionStrings("TakeNoteConnectionString").ConnectionString

            Dim updateSql As String = "INSERT INTO [dbo].[addition]  UserId, fname, lname ,  address1 Value @UserId, @fname, @lname,  @address1"
 

            Using myConnection As New SqlConnection(connectionString)

                myConnection.Open()

                Dim myCommand As New SqlCommand(updateSql, myConnection)

            yCommand.Parameters.AddWithValue("@fname", fname.Text.Trim())

                myCommand.Parameters.AddWithValue("@lname", lname.Text.Trim())

                myCommand.Parameters.AddWithValue("@address1", address1.Text.Trim())

                myCommand.Parameters.AddWithValue("@UserId", user)

                myCommand.ExecuteNonQuery()

                myConnection.Close()

            End Using

        Else

            Response.Redirect("test.aspx")

        End If
 

        'Dim UserSettings As WizardStep = CType(NewUserWizard.FindControl("UserSettings"), WizardStep)WHERE UserId = @UserId

        ' im newUser As MembershipUser = Membership.GetUser(NewUserWizard.UserName)

        ' Programmatically reference the TextBox controls

       

        ' End If
 

    End Sub

Open in new window

0
Comment
Question by:sevensnake77
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24757660
At witch line you got that "error saying Object reference not set to an instance of an object"?
note, i think it`s a copy paste error, but ther is a "yCommand" at line 23...
 
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24757910
myCommand.ExecuteNonQuery()
0
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 24758016
did you try to test your command. remove the parameters and put constant value to test it.
also note:
myCommand.Parameters.AddWithValue("@UserId", user)
shout it be?
myCommand.Parameters.AddWithValue("@UserId", userId)

or userId.toString() or something like this???
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 9

Author Comment

by:sevensnake77
ID: 24763330
No i receive a null value on the return.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24763413
did you try to test your sql command without parameter (ex in "SQL server management studio" if you are using SQL Server)
INSERT INTO [dbo].[addition]  UserId, fname, lname ,  address1 Value `test`, `test`, `test`,  `test`
 
Make sure the sql command is ok. if it is, then the problem is with the connection
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24764146
No its not the connection, But I like to try this again, I have everything on my other computer, I will test all this afternoon, thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now