I saved a procedure in which the updatevalues are first in the table UserSignUpand then insertin the table UserKeyPoints, but my procedure does not execute.
Here is my stored procedure:
CREATE PROC [dbo].[proc_getActivationCode] @ActivationCode VARCHAR(1000)=''
AS
BEGIN
IF EXISTS(SELECT ActivationCode
FROM UserSignUp
WHERE ActivationCode = @ActivationCode
AND Activate = 'False')
BEGIN
DECLARE @UserId INT
SET @userid= (SELECT AutoID
FROM UserSignUp
WHERE ActivationCode = @ActivationCode)
UPDATE UserSignUp
SET Activate = 'Confirm Code'
WHERE ActivationCode = @ActivationCode
INSERT INTO UserKeyPoints
(KeyPoints,
UserId)
VALUES (500,
@userid)
SELECT 1
END
ELSE
BEGIN
SELECT 2
END
END
Here is the C # code where I execute my stored procedure.
if (Request.QueryString["token"] != null)
{
Label1.Text = Request.QueryString["token"];
con.Open();
SqlCommand cmd = new SqlCommand("proc_getActivationCode1", con);
cmd.Parameters.AddWithValue("@ActivationCode", Request.QueryString["token"].ToString());
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dr.Close();
con.Close();
if (dt.Rows[0][0].ToString() == "1")
{
SendEmail objMail = new SendEmail();
}
else
{
Label1.Text = "You are already confirmed.";
}
}
When I execute this code, it starts the procedure without insertand update, and on my page .aspxI get the output Label1ieYou are already confirmed.
Can anyone advise me where I am going wrong?
source
share