Hi,
I have a createuserwizard on my page which is driving me mad
I am linked to sql server. What happens is that when i enter the username which i was trying previously it says choose another username but the thing is the username does not exist in the database as i was just trying prior to creating the db. So it saved it in autocomplete
But when i states the message it then creates that entry that its complaining about.
Seems like it running the page twice.
WHen it says use a different name i put another new one and it does the completion stage
my code is:
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
TextBox firstNameTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("FirstName");
TextBox surNameTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Surname");
TextBox CompanyNameTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("CompanyName");
TextBox TelNumTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("TelNum");
TextBox userNameTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
TextBox passwordTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password");
TextBox emailTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
string userName = userNameTextBox.Text;
string password = passwordTextBox.Text;
string email = emailTextBox.Text;
string firstname = firstNameTextBox.Text;
string companyName = CompanyNameTextBox.Text;
string telNum = TelNumTextBox.Text;
int retValueParam;
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["simransdbConnectionString"].ToString()))
{
SqlCommand spInsertRegisteredUser = new SqlCommand("dbo.Insert_New_User", cn);
spInsertRegisteredUser.CommandType = CommandType.StoredProcedure;
spInsertRegisteredUser.Parameters.Add("@vcUserName", SqlDbType.VarChar).Value = userName;
spInsertRegisteredUser.Parameters.Add("@bpassword", SqlDbType.VarChar).Value = password;
spInsertRegisteredUser.Parameters.Add("@vcCompanyName", SqlDbType.VarChar).Value = companyName;
spInsertRegisteredUser.Parameters.Add("@vcEmail", SqlDbType.VarChar).Value = email;
spInsertRegisteredUser.Parameters.Add("@cFirstName", SqlDbType.Char).Value = firstname;
spInsertRegisteredUser.Parameters.Add("@vcTelephone", SqlDbType.VarChar).Value = telNum;
//SqlParameter rtnVal = spInsertRegisteredUser.Parameters.Add("@ReturnValue", SqlDbType.Int);
// set the direction flag so that it will be filled with the return value
//rtnVal.Direction = ParameterDirection.ReturnValue;
SqlParameter rtnVal = new SqlParameter("@ret", SqlDbType.Int);
rtnVal.Direction = ParameterDirection.ReturnValue;
spInsertRegisteredUser.Parameters.Add(rtnVal);
try
{
cn.Open();
spInsertRegisteredUser.ExecuteNonQuery();
//Response.Redirect("~/default.aspx");
}
catch (Exception ex)
{
throw new Exception("Execption adding account. " + ex.Message);
}
finally
{
cn.Close();
Int32 k = Convert.ToInt32(spInsertRegisteredUser.Parameters["@ret"].Value);
if (k == -1) { label1.Text = k.ToString(); }
// if (bool(ReturnID) = -1)
// {
//then display message that an error has occured
// }
}
}
}
}
SQL Stored procedure is:
USE [simransdb]
GO
/****** Object: StoredProcedure [dbo].[Insert_New_User] Script Date: 07/23/2009 22:06:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Insert_New_User]
@vcUserName varchar(50),
@bpassword varchar(50),
@vcCompanyName varchar(50),
@cFirstName char(50),
@vcEmail varchar(50),
@vcTelephone varchar(50)
AS
BEGIN
SET NOCOUNT ON;
if not exists(select vcUserName from userLogin where vcUserName = @vcUserName)-- to check if a username already exists or not
begin
--insert into userLogin (vcUserName, bpassword)
--values (@vcUserName, @bpassword)
insert into userLogin (vcUserName, bpassword, vcCompanyName, cFirstName, vcEmail, vcTelephoneNum, btApproved)
values (@vcUserName, @bpassword, @vcCompanyName, @cFirstName, @vcEmail, @vcTelephone, 1)
return @@IDENTITY
end
else
return -1
END
RETURN
not sure if its simplier to create my own registration form?
cheers