I am having a problem with trying to insert additional user data in a custom table when using the CreateUserWizard and adding a second step. I get the error (both the asp.net and my custom table (UserInfo) are updated correctly):
Exception Details: System.Data.SqlClient.SqlException: The variable name '@UserID' has already been declared. Variable names must be unique within a query batch or stored procedure.
Source Error:
Line 16: DataSource.InsertParameters.Add("gsgroupid", gsgroupid.Text())
Line 17:
Line 18: DataSource.Insert()
Line 19:
Line 20: |
The vb file is:
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox)Dim DataSource As SqlDataSource = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("SqlDataSource1"), SqlDataSource)
Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)Dim UserGUID As Object = Membership.GetUser(CreateUserWizard1.UserName).ProviderUserKey.ToString()
DataSource.InsertParameters.Add(
"UserID", UserGUID.ToString())DataSource.InsertParameters.Add("UserName", User.ToString())DataSource.InsertParameters.Add("gsgroupid", gsgroupid.Text())
DataSource.Insert()
End Sub
The sql is:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:New_ASPNET %>"
InsertCommand="INSERT INTO [UserInfo] ([UserID], [UserName], [GSGroupID], [FirstName], [LastName], [Address1], [Address2], [City], [State], [Zip], [Country], [PhoneNumber]) VALUES ( @UserID, @UserName, @GSGroupID, @FirstName, @LastName, @Address1, @Address2, @City, @State, @Zip, @Country, @PhoneNumber)"
ProviderName="<%$ConnectionStrings:New_ASPNET.ProviderName %>">
<InsertParameters>
<asp:ControlParameter Name="FirstName" Type="String" ControlID="txtFirstName" />
<asp:ControlParameter Name="LastName" Type="String" ControlID="txtLastName" />
<asp:ControlParameter Name="Address1" Type="String" ControlID="txtstreetAddress" />
<asp:ControlParameter Name="Address2" Type="String" ControlID="txtApartment" />
<asp:ControlParameter Name="City" Type="String" ControlID="txtCity" />
<asp:ControlParameter Name="State" Type="String" ControlID="txtState" />
<asp:ControlParameter Name="Zip" Type="String" ControlID="txtZip" />
<asp:ControlParameter Name="Country" Type="String" ControlID="txtCountry" />
<asp:ControlParameter Name="PhoneNumber" Type="String" ControlID="txtPhoneNumber" />
</InsertParameters>
</asp:SqlDataSource>
If I remove the ["UserID"], @UserID from the sql insert statement, I get the following error:
Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'UserID', table 'C:\INETPUB\WWWROOT\FFL\GS\APP_DATA\ASPNETDB.MDF.dbo.UserInfo'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Source Error:
Line 16: DataSource.InsertParameters.Add("gsgroupid", gsgroupid.Text())
Line 17:
Line 18: DataSource.Insert()
Line 19:
Line 20: This is my first attemp in this area and I just cannot understand how to fix my problem. Any help would be appreciated, Thanks |