Hi All
Getting Procedure 'Create_User' expects parameter '@Password', which was not supplied error
I can't register new user in role based system app, the following code is from register.aspx:
private
void Submit_Click(object sender, System.EventArgs e){
User user;
if (Context.User.Identity.IsAuthenticated)user =
new User(((SiteIdentity)User.Identity).UserID); elseuser =
new User();user.FullName = FullName.Text;
user.Email = Email.Text;
user.Password = Password.Text;
user.Biography = Biography.Text;
if (Context.User.Identity.IsAuthenticated){
user.Update();
Response.Redirect("Default.aspx");
}
else{
if (user.Add() == -1)ErrorMessage.Visible =
true; else{
FormsAuthentication.SetAuthCookie( Email.Text,
true );Response.Redirect("Default.aspx");
}
}
}
The procedure isALTER PROCEDURE
Create_User@FullName
varchar(100),@Password
varchar(16),@Biography
varchar(500)AS
INSERT INTO
Users (FullName, Email, Password, Biography, DateAdded)VALUES
(@FullName, @Email, @Password, @Biography, GETDATE())
Also if some can help me convert this code to vb.net
Don't know much C#
Best Regards
Primillo
Best Regards
Primillo
![]() |
0 |
![]() |
Hi All
The last code breakes in the line when creating a new user:
if (user.Add() == -1)
Any Idea!
Regards
Best Regards
Primillo
![]() |
0 |
![]() |
An INSERT Statement will normally return 1 (one) when the insert was successful. See below for an example of how to check if the new User was successfully inserted into DataBase. I take it for granted that Add() Method is returning an Integer value. Without knowing all the facts here I would probably write my code something like this:private void Submit_Click(object sender, System.EventArgs e) { User user;
// This leads me to ask if you are also using the Form to Update User information?
// Is the SiteIdentity Class your own Class implementation or perhaps a User Control? if (Context.User.Identity.IsAuthenticated) { user = new User(((SiteIdentity)User.Identity).UserID); user.Update(); Response.Redirect("Default.aspx"); Response.End(); } string fullName = FullName.Text; string email = Email.Text; string password = Password.Text; string biography = Biography.Text; user = new User(); user.FullName = fullName; user.Email = email; user.Password = password; user.Biography = biography; int chkInsert = user.Add(); if (chkInsert < 1) { ErrorMessage.Visible = true; return; } FormsAuthentication.SetAuthCookie(email, true); Response.Redirect("Default.aspx"); }
Translating this into VB.Net is really easy. You should try to do it yourself, and I recommend that you learn how to write code in C# as well, as a majority of examples and solutions are presented primarily in C#.
Regards
Andre Colbiornsen
---------------------------------
Seventh Day
Råbygatan 1A,
SE-223 61 Lund
Sweden
Mob.: +46-(0)708-97 78 79
Mail: info@seventhday.se
--------------------------------
![]() |
0 |
![]() |
Hi adec
THX for the code, work ok, after I found the source of the issue:
I add the next two lines to the class User.cs
command.Parameters.Add("@Password", password);
command.Parameters.Add("@Biography", biography);
All code bellow:public
int Add(){
int rowsAffected;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("Create_User", connection);
command.Parameters.Add("@FullName", fullName);
command.Parameters.Add("@Email", email);
// Next two lines added
command.Parameters.Add("@Password", password);command.Parameters.Add("@Biography", biography);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
try
{
rowsAffected = command.ExecuteNonQuery();
}
catch (SqlException sqle)
{
if (sqle.Number == 2627)
return -1;
else
throw sqle;
}
finally
{
command.Dispose();
connection.Close();
}
return rowsAffected;
}
Best Regards
Pura Vida
Primillo
Best Regards
Primillo
![]() |
0 |
![]() |
Adec,
How did you format the code you posted so nicely? Whenever I post code to the forum it's in this ugly font, and I don't get the right spacing like you have in your code. Can you share your secret?Kevin
People are like teabags. You have to put them in hot water to know how strong they are.
![]() |
0 |
![]() |
Just manual labor. I switch to HTML mode, add <pre></pre> tags and paste my code example inside them. Switch back to Design mode and your code looks good, but the colour is gone.
Regards
Andre Colbiornsen
---------------------------------
Seventh Day
Råbygatan 1A,
SE-223 61 Lund
Sweden
Mob.: +46-(0)708-97 78 79
Mail: info@seventhday.se
--------------------------------
![]() |
0 |
![]() |