Solved

membership insert

Posted on 2009-06-30
6
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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