membership insert

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

LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David RobitailleAnalyst ProgrammerCommented:
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
Seven priceFull StackAuthor Commented:
myCommand.ExecuteNonQuery()
0
David RobitailleAnalyst ProgrammerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Seven priceFull StackAuthor Commented:
No i receive a null value on the return.
0
David RobitailleAnalyst ProgrammerCommented:
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
Seven priceFull StackAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.