Hi All,
I Created a Registration Page with only username,Pwd,Email,Contactno and Address fields.
1.when a Enter user with different Email then it is saved the details in Database.
2.My Code is working fine when a Enter username with Already Existing mail id then it is not taking.But only problem is msg is not displaying client side.
How to display msg .Pls find my code also.
procedure:
codebehind:
I Created a Registration Page with only username,Pwd,Email,Contactno and Address fields.
1.when a Enter user with different Email then it is saved the details in Database.
2.My Code is working fine when a Enter username with Already Existing mail id then it is not taking.But only problem is msg is not displaying client side.
How to display msg .Pls find my code also.
procedure:
VB.NET:
CREATE Procedure SP_Login
(
@Username varchar(50),
@pwd varchar(50),
@Email varchar(50),
@ContactNo varchar(50),
@Address varchar(50),
@Ret_val Int = Null Out,
@Ret_msg Varchar(75) = Null Out
)
AS
IF EXISTS(SELECT * FROM Login WHERE Email=@Email)
BEGIN
RAISERROR('The email address already exists', 16, 1)
END
ELSE
BEGIN
INSERT INTO Login (Username,pwd,Email,ContactNo,Address)VALUES(@Username,@pwd,@Email,@ContactNo,@Address)
END
If @@Error = 0
BEGIN
SET @RET_VAL = 1
SET @RET_MSG = 'DETAILS INSERTED SUCCESSFULLY.'
END
ELSE
BEGIN
SET @RET_VAL = 0
SET @RET_MSG = 'ERROR : Error in Inserting Details.'
END
GO
VB.NET:
Try
conObj = New SqlConnection("Data Source=B4B-2F-323-CK26;user id=sa;password=sa;Database=TEST")
conObj.Open()
tranObj = conObj.BeginTransaction
cmdObj = conObj.CreateCommand
cmdObj.Transaction = tranObj
With cmdObj
.CommandText = "SP_Login"
.CommandType = CommandType.StoredProcedure
End With
With cmdObj.Parameters
.Add(New SqlParameter("@UserName", SqlDbType.VarChar, 50)).Value = txtUserName.Text
.Add(New SqlParameter("@pwd", SqlDbType.VarChar, 50)).Value = txtPwd.Text
.Add(New SqlParameter("@ContactNo", SqlDbType.VarChar, 50)).Value = txtPhoneno.Text
.Add(New SqlParameter("@Email", SqlDbType.VarChar, 50)).Value = txtEmail.Text
.Add(New SqlParameter("@Address", SqlDbType.VarChar, 50)).Value = txtAddress.Text
retvalp = .Add("@RET_VAL", SqlDbType.Int)
retvalp.Direction = ParameterDirection.Output
retmsgp = .Add("@RET_MSG", SqlDbType.VarChar, 50)
retmsgp.Direction = ParameterDirection.Output
End With
cmdObj.ExecuteNonQuery()
If retvalp.Value = 1 Then
tranObj.Commit()
lblmsg.Text = retmsgp.Value
Else
tranObj.Rollback()
lblmsg.Text = retmsgp.Value
End If
Catch ex As Exception
Response.Write(ex.ToString())
Finally
If Not tranObj Is Nothing Then tranObj.Dispose()
conObj.Close()
cmdObj.Dispose()
End Try
Last edited by a moderator: