Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

visual studio jumps code!!!!!

$
0
0

okay, this is one of the weirdest things i have ever seen...so i have created a registration page to my code which on submit it will fire the following codes

        protected void btsSubmit_Click(object sender, EventArgs e)
        {
            if (tbxFName.Text.Trim().Length == 0 || tbxLName.Text.Trim().Length == 0 || tbxUsername.Text.Trim().Length == 0 || tbxPassword.Text.Length == 0)
                ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "ShowNotification('Warning','Please fill the required textboxes');", true);
            else
            {
                try
                {
                    string conString = ConfigurationManager.ConnectionStrings["IRELDBCS"].ConnectionString;
                    using (SqlConnection con = new SqlConnection(conString))
                    {
                        SqlCommand sc = new SqlCommand("spUserRegister", con);
                        sc.CommandType = CommandType.StoredProcedure;

                        sc.Parameters.AddWithValue("@a", tbxFName.Text.Trim());
                        sc.Parameters.AddWithValue("@b", tbxLName.Text.Trim());
                        sc.Parameters.AddWithValue("@c", tbxUsername.Text.Trim());
                        sc.Parameters.AddWithValue("@d", tbxPassword.Text);
                        sc.Parameters.AddWithValue("@e", ddlUserType.SelectedValue);
                        con.Open();
                        int ReturnCode = (int)sc.ExecuteScalar();
                        if (ReturnCode == -1)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "ShowNotification('Error','This user is already exists.');", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "ShowNotification('Success','you registration was successful');", true);                            
                        }
                    }
                }
                catch
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "ShowNotification('Error','Something went wrong, please try again in a few minutes');", true);
                }
            }            
        }

i was using sc.ExecuteNonQuery(); instead of int ReturnCode = (int)sc.ExecuteScalar(); and it was working fine and it was functioning till i have added the part which it stops user from registering with the same email address which is 

int ReturnCode = (int)sc.ExecuteScalar();
if (ReturnCode == -1)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "ShowNotification('Error','This user is already exists.');", true);
}
else
{
   ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "ShowNotification('Success','you registration was successful');", true);                            
}

and this is my stored procedure

USE [dbo.IrELearn]
GO
/****** Object:  StoredProcedure [dbo].[spUserRegister]    Script Date: 04/01/2014 19:35:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spUserRegister]
   (
	@a nvarchar(30), 
	@b nvarchar(50), 
	@c nvarchar(150), 
	@d nvarchar(30), 
	@e smallint
	
   )
as
BEGIN
	declare @Count int
	declare @ReturnCode int

	SELECT @Count = COUNT(Username)
	FROM tbl_Users WHERE Username = @C
	IF @Count > 0
	Begin
		Set @ReturnCode = -1
	End
	Else
	Begin
		Set @ReturnCode = 1	
		INSERT INTO tbl_Users (FirstName, LastName, Username, Password, UserType) VALUES (@a,@b,@a,@b,@e)
	End
	SELECT @ReturnCode as ReturnValue
END

now users cant register anymore and when i tried to debug and find where the problem is, it complitly skips the if section after 

int ReturnCode = (int)sc.ExecuteScalar();

im not sure whats goin on!! can anyone find out what the problem is?

thank you in advance


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>