Im trying to make an "createaccount-page" and followed this guide:http://aspnet.4guysfromrolla.com/articles/070506-1.aspx
The problem is that I want to use a stored procedure instead...But Iam getting this message when pushing the create-button:
"Procedure or function usp_MyProcedure has too many arguments specified"
My stored procedure look like this: (maybe something is wrong here?)
ALTER PROCEDURE
usp_MyProcedure
(
@.UserID
uniqueidentifier OUTPUT,@.FName
varchar(50),@.LName
varchar(50),)
AS
INSERT INTO MyTable (UserID, FName, LName,)Values
(@.UserID, @.FName, @.LName)
RETURN
My sqldatasource:
<asp:SqlDataSourceID="InsertExtraInfo"runat="server"ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString.ProviderName %>"InsertCommand="usp_MyProcedure"InsertCommandType="StoredProcedure"><InsertParameters><asp:ControlParameterName="FName"Type="String"ControlID="tboxFName"PropertyName="Text"/><asp:ControlParameterName="LName"Type="String"ControlID="tboxLName"PropertyName="Text"/></InsertParameters></asp:SqlDataSource>The code behind-file is the same as the one in the article...Ok..Now I dont understand...because I have the same sql-code as they use...(I wait with the stored procedure until it first works)....
Everything is saved in the database, but I get this message: "The variable name '@.UserId' has already been declared. Variable names must be unique within a query batch or stored procedure"
My sqldatasource look like this now:
<
asp:SqlDataSourceID="InsertExtraInfo"runat="server"ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString.ProviderName %>"InsertCommand="INSERT INTO [MyTable] (UserId, FName, LName) VALUES (@.UserID, @.FName, @.LName)"><InsertParameters><asp:ControlParameterName="FName"Type="String"ControlID="tboxFName"PropertyName="Text"/><asp:ControlParameterName="LName"Type="String"ControlID="tboxLName"PropertyName="Text"/></InsertParameters></asp:SqlDataSource>|||Where is your code to get the value for your UserId InsertParameter?
You need something like this in your code for inserting:
...
InsertExtraInfo.InsertParameters.Add("UserId", System.GUID.NewGuid().ToString());
InsertExtraInfo.Insert();
...
Because I didnt get this to work, I choosed to use profiles instead...I use this code in my code-behind-file:
Protected
Sub CreateUserWizard1_CreatedUser(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CreateUserWizard1.CreatedUser' Create an empty Profile for the newly created userDim ProfileAs ProfileCommon =CType(ProfileCommon.Create(CreateUserWizard1.UserName,True), ProfileCommon)' Populate some Profile properties off of the create user wizardProfile.FirstName =
CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("tboxFNamn"), TextBox).TextProfile.LastName =
CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("tboxLNamn"), TextBox).Text' Save the profile - must be done since we explicitly created this profile instanceProfile.Save()
EndSub' Activate event fires when the user hits "next" in the CreateUserWizardPublicSub AssignUserToRoles_Activate(ByVal senderAsObject,ByVal eAs EventArgs)' Databind list of roles in the role manager system to a listbox in the wizardAvailableRoles.DataSource = Roles.GetAllRoles
AvailableRoles.DataBind()
EndSub' Deactivate event fires when user hits "next" in the CreateUserWizardPublicSub AssignUserToRoles_Deactivate(ByVal senderAsObject,ByVal eAs EventArgs)' Add user to all selected roles from the roles listboxDim iAsInteger = 0DoWhile (i < AvailableRoles.Items.Count)If (AvailableRoles.Items(i).Selected =True)ThenRoles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items(i).Value)
EndIfi = (i + 1)
LoopEndSub
..The values from the textboxes is correctly saved in the table (aspnet_Profile), but the roles is not saved in aspnet_UsersInRoles..(for it should be saved there right?)...
Becuase the listbox called "AvailibleRoles" shows the all roles that the "new user" could use...And that role needs to be saved somewhere..(I think in the aspnet_UsersInRoles)...But its not saved there...
So what should I do to save it?
No comments:
Post a Comment