I am using the following stored procedure to check if email exists before adding the record.
My codebehind is:
Whenever I register trying to register someone with an email address that already exists, it doesnt add the record but it seems to then redirect them as if they have logged in.
How can I display a message in a label somewhere that says 'Email address already exists'
Code:
USE [quickbabysit]
GO
/****** Object: StoredProcedure [dbo].[AddNewBabysitterRegistration] Script Date: 05/12/2012 13:11:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddNewBabysitterRegistration]
(
@BabysitterID int OUTPUT,
@Firstname varchar(150),
@Surname varchar(150),
@EmailAddress nvarchar(max),
@Password nchar(8),
@AddressLine1 varchar(150),
@AddressLine2 varchar(150),
@AddressLine3 varchar(150),
@AddressLine4 varchar(150),
@Town varchar(150),
@Postcode varchar(20),
@DateofBirth datetime,
@Gender varchar(10),
@ContactPhone varchar(20),
@Availability varchar(50),
@Visa varchar(4),
@CRB varchar(4)
)
AS
BEGIN
IF NOT EXISTS(SELECT *
FROM dbo.Babysitters
WHERE ( @EmailAddress = dbo.Babysitters.EmailAddress
)
)
BEGIN
INSERT INTO dbo.Babysitters
(Firstname
,Surname
, EmailAddress
, Password
, AddressLine1
, AddressLine2
, AddressLine3
, AddressLine4
, Town
, Postcode
, DateofBirth
, Gender
, ContactPhone
, Availability
, Visa
, CRB )
VALUES
(@Firstname,
@Surname,
@EmailAddress,
@Password,
@AddressLine1,
@AddressLine2,
@AddressLine3,
@AddressLine4,
@Town,
@Postcode,
@DateofBirth,
@Gender,
@ContactPhone,
@Availability,
@Visa,
@CRB)
END
END
My codebehind is:
Code:
Protected Sub btnRegister_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles btnRegister.Click
If Me.chkTerms.Checked = True Then
'Add record here
Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("quickbabysitConnectionString").ConnectionString
Dim con As New SqlConnection(ConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "AddNewBabysitterRegistration"
cmd.Parameters.Add("@Firstname", SqlDbType.VarChar).Value = txtFirstname.Text.Trim()
cmd.Parameters.Add("@Surname", SqlDbType.VarChar).Value = txtSurname.Text.Trim()
cmd.Parameters.Add("@EmailAddress", SqlDbType.NVarChar).Value = txtEmail.Text.Trim()
cmd.Parameters.Add("@Password", SqlDbType.NChar).Value = txtPassword.Text.Trim()
cmd.Parameters.Add("@AddressLine1", SqlDbType.VarChar).Value = txtAddress.Text.Trim()
cmd.Parameters.Add("@AddressLine2", SqlDbType.VarChar).Value = txtAddress2.Text.Trim()
cmd.Parameters.Add("@AddressLine3", SqlDbType.VarChar).Value = txtAddress3.Text.Trim()
cmd.Parameters.Add("@AddressLine4", SqlDbType.VarChar).Value = txtAddress4.Text.Trim()
cmd.Parameters.Add("@Town", SqlDbType.VarChar).Value = txtCity.Text.Trim()
cmd.Parameters.Add("@Postcode", SqlDbType.VarChar).Value = txtPostcode.Text.Trim()
cmd.Parameters.Add("@DateofBirth", SqlDbType.DateTime).Value = txtDateofBirth.Text.Trim()
cmd.Parameters.Add("@Gender", SqlDbType.VarChar).Value = ddlGender.SelectedItem.Text.Trim()
cmd.Parameters.Add("@ContactPhone", SqlDbType.VarChar).Value = txtPhone.Text.Trim()
cmd.Parameters.Add("@Availability", SqlDbType.VarChar).Value = rblAvailability.SelectedValue.Trim()
cmd.Parameters.Add("@Visa", SqlDbType.VarChar).Value = rblVisa.SelectedValue.Trim()
cmd.Parameters.Add("@CRB", SqlDbType.VarChar).Value = rblCRB.SelectedValue.Trim()
Session("UserID") = txtEmail.Text
Session("UserType") = "Babysitter"
Dim BabysitterID As New SqlParameter("@BabysitterID", SqlDbType.Int)
BabysitterID.Direction = ParameterDirection.Output
cmd.Parameters.Add(BabysitterID)
cmd.Connection = con
Try
con.Open()
cmd.ExecuteScalar()
Catch ex As Exception
Throw ex
Finally
con.Close()
con.Dispose()
End Try
Dim MyReg As String = Convert.ToString(BabysitterID.Value)
Me.txtRegID.Text = MyReg
GetFile()
UpdateCVStatus()
send_emailSitter()
pnlRegSitter.Visible = False
pnlSuccess.Visible = True
FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, False)
'Response.AddHeader("Refresh", "4;URL=babysitters/home.aspx")
Response.Redirect("babysitters/home.aspx")
Else
Me.lblTerms.Visible = True
End If
End Sub
Whenever I register trying to register someone with an email address that already exists, it doesnt add the record but it seems to then redirect them as if they have logged in.
How can I display a message in a label somewhere that says 'Email address already exists'