Link to home
Start Free TrialLog in
Avatar of cer_petsafe
cer_petsafeFlag for United States of America

asked on

sqlDataSource.InsertParameter type conversion problem

I'm trying to add a parameter to an sqlDataSource from VB code behind.  The parameter value is the MembershipUser.ProviderUserKey.tostring.  I'm getting the following error:

"Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query."

I've tried CAST and CONVERT to no success.
Private Sub CreateUserWizard1_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
        Dim UserNameTextBox As TextBox = CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName")
        Dim DataSource As SqlDataSource = CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo")
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim UserGUID As Object = User.ProviderUserKey
        DataSource.InsertParameters("UserId").DefaultValue = UserGUID.ToString
        DataSource.Insert()
    End Sub
 
.........................................................
 
 
   <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                                InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) 
                                                               VALUES (CAST(@UserId AS VARBINARY), @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
                                                <InsertParameters>
                                                    <asp:Parameter Name="UserId"/>
                                                    <asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
                                                </InsertParameters>
                                            </asp:SqlDataSource>

Open in new window

Avatar of guru_sami
guru_sami
Flag of United States of America image

why do you have  CAST(@UserId AS VARBINARY in your InsertCommand?
What Type is it in the DB?
Change VARBINARY  to Varchar if you want to store string
Also if you are linking it to default membership aspnet_users table ..UserId in your user Profile table should be uniqueidentifier.
Check this for linking aspnet_Users table with another table to store additional user information:

http://www.asp.net/learn/security/tutorial-08-vb.aspx

what is type in your DB for UserID ?




 <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                                InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) 
                                                               VALUES (CAST(@UserId AS VARBINARY), @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
                                                <InsertParameters>
                                                    <asp:Parameter Name="UserId" DbType="Guid"/>
                                                    <asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
                                                </InsertParameters>
                                            </asp:SqlDataSource>

Open in new window


 <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                                InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) 
                                                               VALUES (@UserId, @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
                                                <InsertParameters>
                                                    <asp:Parameter Name="UserId" DbType="Guid"/>
                                                    <asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
                                                </InsertParameters>
                                            </asp:SqlDataSource>

Open in new window

Avatar of cer_petsafe

ASKER

the type in the DB is uniqueidentifier.  I've tried  DbType="Guid" or Type="Object", still no luck!
<asp:Parameter Name="UserId" DbType="Guid" Type="String"/>

Error: "The Type property of parameter 'UserId' cannot be set when the DbType property is set."
This is what you should be doing:
1: Remove this <asp:Parameter Name="UserId" DbType="Guid"/> from your    <InsertParameters>
2:Then adjust your code behind like below:
        Dim UserGUID As Stiring = User.ProviderUserKey.ToString
        DataSource.InsertParameters.Add("UserId", DbType.Guid, UserGUID)
        DataSource.Insert()

                                                 
sorry guru_sami,  

I still get the original data type conversion error.  I started with code very similar to that and switch hoping it would work.  But it really does the same thing, just in different order.  
alrite how about posting your current complete code here once again.
There must be something else at play here, because stepping through the code, everything works right up the insert().  Does it matter if the sqlDataSource is with in the ContentTemplate of the CreateUserWizardSetp?
here is everything!

Public Partial Class NewUser
    Inherits System.Web.UI.Page
 
    Private Sub CreateUserWizard1_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
        Dim UserNameTextBox As TextBox = CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName")
        Dim DataSource As SqlDataSource = CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo")
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim UserGUID As String = User.ProviderUserKey.ToString
        'DataSource.InsertParameters("UserId").DefaultValue = UserGUID.ToString
        DataSource.InsertParameters.Add("UserId", UserGUID)
        DataSource.Insert()
    End Sub
 
End Class
 
 
..................................
 
 
 
<body>
    <form id="form1" runat="server">
        <asp:Panel Id="outerPanel" runat="server" ScrollBars="none" BorderColor="#E0E0E0" BorderWidth="1" Width="600" Height="470">
            <asp:Panel runat="server" ID="innerPanel">
                <asp:Table runat="server" BackColor='Transparent' >
                    <asp:TableRow >
                        <asp:TableCell BorderColor='Transparent' BorderWidth='0' Width='10'>
                        </asp:TableCell>
                        <asp:TableCell BorderColor='Transparent' BorderWidth='0' VerticalAlign='Top'>
                            <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" ContinueDestinationPageUrl="~/Home.aspx" RequireEmail="true"
                             StepNextButtonImageUrl="Images/Web/NEXT.JPG" StepNextButtonType="Image" StepNextButtonStyle-Height="20" 
                              FinishPreviousButtonImageUrl="Images/Web/PREVIOUS.JPG" FinishPreviousButtonType="Image" FinishPreviousButtonStyle-Width="20"
                             StepPreviousButtonImageUrl="Images/Web/PREVIOUS.JPG" StepPreviousButtonType="Image" StepPreviousButtonStyle-Height="20" 
                             CreateUserButtonImageUrl="Images/Web/CREATE.JPG" CreateUserButtonType="Image" CreateUserButtonStyle-Height="20"
                              ContinueButtonImageUrl="Images/Web/CONTINUE.JPG" ContinueButtonType="Image" ContinueButtonStyle-Height="20" 
                               StartNextButtonImageUrl="Images/Web/NEXT.JPG" StartNextButtonType="Image" StartNextButtonStyle-Height="20"  >
                                <TitleTextStyle Font-Size="small" Font-Bold="true" HorizontalAlign="Center" BorderWidth="10" ForeColor="#b12621" />
                                <TextBoxStyle  BorderColor="#808080" BackColor="#E0E0E0" BorderWidth="1"  BorderStyle="Solid"/>
                                <WizardSteps>
                                   <asp:WizardStep ID="CreateUserWizardStep1" runat="server">
                                        <table>
                                            <tr>
                                                <th><label class="o2">New Account Information</label></th>
                                            </tr>
                                             <tr>
                                                <td>First Name:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="FirstName" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="FirstName"
                                                         ErrorMessage="First Name is required." />
                                                </td>
                                            </tr> 
                                             <tr>
                                                <td>Last Name:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="LastName" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0"  /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="LastName"
                                                         ErrorMessage="Last Name is required." />
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td>Address:</td>
                                                <td>
                                                
                                                    <asp:TextBox runat="server" ID="ShippingAddress" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td>City:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="ShippingCity" MaxLength="50" Columns="15" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr>  
                                            <tr>
                                                <td>State:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="ShippingState" MaxLength="25" Columns="10" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr>   
                                            <tr>
                                                <td>Zip:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="ShippingZip" MaxLength="10" Columns="10" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator8" ControlToValidate="ShippingZip"
                                                         ErrorMessage="Zip Code is required." />
                                                </td>
                                            </tr>
                                             <tr>
                                                <td>Phone Number:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="Phone" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr> 
                                        </table>
                                        <p>Sign up now to recieve access to detailed 
                                        iHouse decking configurations and the ability to
                                        quote and purchase kits and products. Registration
                                        is free and there are no obligations.</p>
                                        <p></p><p></p>
                                        <label class="o3">* Fields are required.</label>
                                    </asp:WizardStep>
                                    <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server">
                                        <ContentTemplate>
                                            <table>
                                                <tr>
                                                    <th>User Information</th>
                                                </tr>
                                                <tr>
                                                    <td>Username:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="UserName" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName" 
                                                            ErrorMessage="Username is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Password:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Password" TextMode="Password" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password" 
                                                            ErrorMessage="Password is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Confirm Password:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword" 
                                                            ErrorMessage="Confirm Password is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Email:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Email" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator11" ControlToValidate="Email" 
                                                            ErrorMessage="Email is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Question:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Question" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question" 
                                                            ErrorMessage="Question is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Answer:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Answer" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer" 
                                                            ErrorMessage="Answer is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                         <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                                                ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                                    </td>
                                                </tr>
                                            </table>
                                            <p></p>
                                            <label class="o3">* Fields are required.</label>
                                            <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                                InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) 
                                                               VALUES (@UserId, @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
                                                <InsertParameters>
                                                    <asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
                                                </InsertParameters>
                                            </asp:SqlDataSource>
                                        </ContentTemplate>
                                    </asp:CreateUserWizardStep>
                                    <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" AllowReturn="true" />
                                </WizardSteps>
                            </asp:CreateUserWizard>
                           
                            
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </asp:Panel> 
        </asp:Panel>
    </form>
</body>

Open in new window


Public Partial Class NewUser
    Inherits System.Web.UI.Page
 
    Private Sub CreateUserWizard1_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
        Dim UserNameTextBox As TextBox = CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName")
        Dim DataSource As SqlDataSource = CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo")
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        DataSource.InsertParameters.Add("UserId", User.ProviderUserKey)
        DataSource.Insert()
    End Sub
 
End Class
 
 
..................................
 
 
 
<body>
    <form id="form1" runat="server">
        <asp:Panel Id="outerPanel" runat="server" ScrollBars="none" BorderColor="#E0E0E0" BorderWidth="1" Width="600" Height="470">
            <asp:Panel runat="server" ID="innerPanel">
                <asp:Table runat="server" BackColor='Transparent' >
                    <asp:TableRow >
                        <asp:TableCell BorderColor='Transparent' BorderWidth='0' Width='10'>
                        </asp:TableCell>
                        <asp:TableCell BorderColor='Transparent' BorderWidth='0' VerticalAlign='Top'>
                            <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" ContinueDestinationPageUrl="~/Home.aspx" RequireEmail="true"
                             StepNextButtonImageUrl="Images/Web/NEXT.JPG" StepNextButtonType="Image" StepNextButtonStyle-Height="20" 
                              FinishPreviousButtonImageUrl="Images/Web/PREVIOUS.JPG" FinishPreviousButtonType="Image" FinishPreviousButtonStyle-Width="20"
                             StepPreviousButtonImageUrl="Images/Web/PREVIOUS.JPG" StepPreviousButtonType="Image" StepPreviousButtonStyle-Height="20" 
                             CreateUserButtonImageUrl="Images/Web/CREATE.JPG" CreateUserButtonType="Image" CreateUserButtonStyle-Height="20"
                              ContinueButtonImageUrl="Images/Web/CONTINUE.JPG" ContinueButtonType="Image" ContinueButtonStyle-Height="20" 
                               StartNextButtonImageUrl="Images/Web/NEXT.JPG" StartNextButtonType="Image" StartNextButtonStyle-Height="20"  >
                                <TitleTextStyle Font-Size="small" Font-Bold="true" HorizontalAlign="Center" BorderWidth="10" ForeColor="#b12621" />
                                <TextBoxStyle  BorderColor="#808080" BackColor="#E0E0E0" BorderWidth="1"  BorderStyle="Solid"/>
                                <WizardSteps>
                                   <asp:WizardStep ID="CreateUserWizardStep1" runat="server">
                                        <table>
                                            <tr>
                                                <th><label class="o2">New Account Information</label></th>
                                            </tr>
                                             <tr>
                                                <td>First Name:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="FirstName" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="FirstName"
                                                         ErrorMessage="First Name is required." />
                                                </td>
                                            </tr> 
                                             <tr>
                                                <td>Last Name:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="LastName" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0"  /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="LastName"
                                                         ErrorMessage="Last Name is required." />
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td>Address:</td>
                                                <td>
                                                
                                                    <asp:TextBox runat="server" ID="ShippingAddress" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td>City:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="ShippingCity" MaxLength="50" Columns="15" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr>  
                                            <tr>
                                                <td>State:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="ShippingState" MaxLength="25" Columns="10" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr>   
                                            <tr>
                                                <td>Zip:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="ShippingZip" MaxLength="10" Columns="10" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator8" ControlToValidate="ShippingZip"
                                                         ErrorMessage="Zip Code is required." />
                                                </td>
                                            </tr>
                                             <tr>
                                                <td>Phone Number:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="Phone" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr> 
                                        </table>
                                        <p>Sign up now to recieve access to detailed 
                                        iHouse decking configurations and the ability to
                                        quote and purchase kits and products. Registration
                                        is free and there are no obligations.</p>
                                        <p></p><p></p>
                                        <label class="o3">* Fields are required.</label>
                                    </asp:WizardStep>
                                    <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server">
                                        <ContentTemplate>
                                            <table>
                                                <tr>
                                                    <th>User Information</th>
                                                </tr>
                                                <tr>
                                                    <td>Username:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="UserName" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName" 
                                                            ErrorMessage="Username is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Password:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Password" TextMode="Password" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password" 
                                                            ErrorMessage="Password is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Confirm Password:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword" 
                                                            ErrorMessage="Confirm Password is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Email:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Email" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator11" ControlToValidate="Email" 
                                                            ErrorMessage="Email is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Question:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Question" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question" 
                                                            ErrorMessage="Question is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Answer:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Answer" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer" 
                                                            ErrorMessage="Answer is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                         <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                                                ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                                    </td>
                                                </tr>
                                            </table>
                                            <p></p>
                                            <label class="o3">* Fields are required.</label>
                                            <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                                InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) 
                                                               VALUES (@UserId, @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
                                                <InsertParameters>
                                                    <asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
                                                </InsertParameters>
                                            </asp:SqlDataSource>
                                        </ContentTemplate>
                                    </asp:CreateUserWizardStep>
                                    <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" AllowReturn="true" />
                                </WizardSteps>
                            </asp:CreateUserWizard>
                           
                            
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </asp:Panel> 
        </asp:Panel>
    </form>
</body>

Open in new window


Public Partial Class NewUser
    Inherits System.Web.UI.Page
 
    Private Sub CreateUserWizard1_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
        Dim UserNameTextBox As TextBox = CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName")
        Dim DataSource As SqlDataSource = CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo")
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim guiduserid As Guid = CType(User.ProviderUserKey, Guid)
        DataSource.InsertParameters.Add("UserId", guiduserid)
        DataSource.Insert()
    End Sub
 
End Class
 
 
..................................
 
 
 
<body>
    <form id="form1" runat="server">
        <asp:Panel Id="outerPanel" runat="server" ScrollBars="none" BorderColor="#E0E0E0" BorderWidth="1" Width="600" Height="470">
            <asp:Panel runat="server" ID="innerPanel">
                <asp:Table runat="server" BackColor='Transparent' >
                    <asp:TableRow >
                        <asp:TableCell BorderColor='Transparent' BorderWidth='0' Width='10'>
                        </asp:TableCell>
                        <asp:TableCell BorderColor='Transparent' BorderWidth='0' VerticalAlign='Top'>
                            <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" ContinueDestinationPageUrl="~/Home.aspx" RequireEmail="true"
                             StepNextButtonImageUrl="Images/Web/NEXT.JPG" StepNextButtonType="Image" StepNextButtonStyle-Height="20" 
                              FinishPreviousButtonImageUrl="Images/Web/PREVIOUS.JPG" FinishPreviousButtonType="Image" FinishPreviousButtonStyle-Width="20"
                             StepPreviousButtonImageUrl="Images/Web/PREVIOUS.JPG" StepPreviousButtonType="Image" StepPreviousButtonStyle-Height="20" 
                             CreateUserButtonImageUrl="Images/Web/CREATE.JPG" CreateUserButtonType="Image" CreateUserButtonStyle-Height="20"
                              ContinueButtonImageUrl="Images/Web/CONTINUE.JPG" ContinueButtonType="Image" ContinueButtonStyle-Height="20" 
                               StartNextButtonImageUrl="Images/Web/NEXT.JPG" StartNextButtonType="Image" StartNextButtonStyle-Height="20"  >
                                <TitleTextStyle Font-Size="small" Font-Bold="true" HorizontalAlign="Center" BorderWidth="10" ForeColor="#b12621" />
                                <TextBoxStyle  BorderColor="#808080" BackColor="#E0E0E0" BorderWidth="1"  BorderStyle="Solid"/>
                                <WizardSteps>
                                   <asp:WizardStep ID="CreateUserWizardStep1" runat="server">
                                        <table>
                                            <tr>
                                                <th><label class="o2">New Account Information</label></th>
                                            </tr>
                                             <tr>
                                                <td>First Name:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="FirstName" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="FirstName"
                                                         ErrorMessage="First Name is required." />
                                                </td>
                                            </tr> 
                                             <tr>
                                                <td>Last Name:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="LastName" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0"  /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="LastName"
                                                         ErrorMessage="Last Name is required." />
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td>Address:</td>
                                                <td>
                                                
                                                    <asp:TextBox runat="server" ID="ShippingAddress" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr> 
                                            <tr>
                                                <td>City:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="ShippingCity" MaxLength="50" Columns="15" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr>  
                                            <tr>
                                                <td>State:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="ShippingState" MaxLength="25" Columns="10" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr>   
                                            <tr>
                                                <td>Zip:</td>
                                                <td>
                                                    
                                                    <asp:TextBox runat="server" ID="ShippingZip" MaxLength="10" Columns="10" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator8" ControlToValidate="ShippingZip"
                                                         ErrorMessage="Zip Code is required." />
                                                </td>
                                            </tr>
                                             <tr>
                                                <td>Phone Number:</td>
                                                <td>
                                                    <asp:TextBox runat="server" ID="Phone" MaxLength="50" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" />
                                                </td>
                                            </tr> 
                                        </table>
                                        <p>Sign up now to recieve access to detailed 
                                        iHouse decking configurations and the ability to
                                        quote and purchase kits and products. Registration
                                        is free and there are no obligations.</p>
                                        <p></p><p></p>
                                        <label class="o3">* Fields are required.</label>
                                    </asp:WizardStep>
                                    <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server">
                                        <ContentTemplate>
                                            <table>
                                                <tr>
                                                    <th>User Information</th>
                                                </tr>
                                                <tr>
                                                    <td>Username:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="UserName" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName" 
                                                            ErrorMessage="Username is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Password:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Password" TextMode="Password" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password" 
                                                            ErrorMessage="Password is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Confirm Password:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" BorderWidth="1" BorderColor="#808080" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword" 
                                                            ErrorMessage="Confirm Password is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Email:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Email" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator11" ControlToValidate="Email" 
                                                            ErrorMessage="Email is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Question:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Question" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question" 
                                                            ErrorMessage="Question is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Answer:</td>
                                                    <td>
                                                        
                                                        <asp:TextBox runat="server" ID="Answer" BorderColor="#808080" BorderWidth="1" BackColor="#E0E0E0" /><label class="o2">*</label>
                                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer" 
                                                            ErrorMessage="Answer is required." />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                         <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                                                ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                                    </td>
                                                </tr>
                                            </table>
                                            <p></p>
                                            <label class="o3">* Fields are required.</label>
                                            <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
                                                InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip]) 
                                                               VALUES (@UserId, @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
                                                <InsertParameters>
                                                    <asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
                                                    <asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
                                                    <asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
                                                </InsertParameters>
                                            </asp:SqlDataSource>
                                        </ContentTemplate>
                                    </asp:CreateUserWizardStep>
                                    <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" AllowReturn="true" />
                                </WizardSteps>
                            </asp:CreateUserWizard>
                           
                            
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </asp:Panel> 
        </asp:Panel>
    </form>
</body>

Open in new window

"Conversion from type 'Guid' to type 'String' is not valid."
try my last comment.
InsertParameters take String as value:
 DataSource.InsertParameters.Add("UserId", guiduserid.ToString)
Nope!  In all cases I can see the string value of the guid when I step through the code.  It errors on DataSource.Insert() which tells me its a sql thing.
I had one more look and with these settings it should work:
Having SqlDataSource inside the CUW is not a problem.
Just few more questions for you:
1: Are you getting the same error with the code given below?
2: Are your sure its not other parameters causing problem?
3: Can you use Sql Profiler and see whats going on....

Note: I did not make any chages to code below ... but this is the code you provided last time and I couldn't see anything wrong in there.

<asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
 InsertCommand="INSERT INTO [UserAddresses] ([UserId], [FirstName], [LastName], [Phone], [ShippingAddress], [ShippingCity], [ShippingState], [ShippingZip])
 VALUES (@UserId, @FirstName, @LastName, @Phone, @ShippingAddress, @ShippingCity, @ShippingState, @ShippingZip)"
ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>">
<InsertParameters>
<asp:ControlParameter Name="FirstName" Type="String" ControlID="FirstName" PropertyName="Text" />
<asp:ControlParameter Name="LastName" Type="String" ControlID="LastName" PropertyName="Text" />
<asp:ControlParameter Name="Phone" Type="String" ControlID="Phone" PropertyName="Text" />
<asp:ControlParameter Name="ShippingAddress" Type="String" ControlID="ShippingAddress" PropertyName="Text" />
<asp:ControlParameter Name="ShippingCity" Type="String" ControlID="ShippingCity" PropertyName="Text" />
<asp:ControlParameter Name="ShippingState" Type="String" ControlID="ShippingState" PropertyName="Text" />
<asp:ControlParameter Name="ShippingZip" Type="String" ControlID="ShippingZip" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>

-------------
Private Sub CreateUserWizard1_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim UserNameTextBox As TextBox = CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName")
Dim DataSource As SqlDataSource = CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo")
Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
Dim UserGUID As String = User.ProviderUserKey.ToString
DataSource.InsertParameters.Add("UserId", UserGUID)
DataSource.Insert()
End Sub

guru_sami

1. yes this code gives me the same error.
2. there are no other parameters being inserted in this manner, You have the entire code.
3. I'll have to look into using Sql Profiler, I never used it before.
sorry...we have so many errors one after another....can you tell the last error message you are observing...because I do not see any reason for UserId to parameter to throw any error as the code looks fine.
May be also can you confirm you have UserId= uniqueidentifier in your DB as well.
The latest error is also the first:
"Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query."
...and yes the UserId type is uniqueidentifier.  

Unfortunately, I'm no longer at work today, so I'll have to tackle this again tomorrow.
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK I solved the problem by creating a new table.  It is exactly the same as the previous, so I'm not sure why  the new one works and the old one does not.  I'm awarding points to both 'jinal' and 'guru_sami' because I believe both had equally contributed and both had solutions that SHOULD have worked.