I HAVE A SCANERI THAT THER IS DEFAULT ADMIN IN TABLE AND THIS ADMIN ADD FURHTER SUPERVIOSR,MANAGERS AND SENIOR MANAGERS THEN WHEN ADMIN FIRST TIME LOGIN AND CREATE ACCOUNTS OF SUPERVISOR,MANAGER,DIRECTOR

AND HERE IS THE TABLE

UserID  UserName Password UserTypeID    DepID   FullName CreateDate DocID   Email                     PhoneNumber   DesigID
51  Noreen  Fatima      2          NULL NULL    2014-02-04  NULL    noreen.fatimaa@gmail.com    324234234   4
52  Admin   Docum       1          NULL NULL    NULL    NULL    NULL                                        3
53  Sundus   Khan       1           2   NULL    2014-02-04  NULL    Sunduskhan@hotmail.com  031545646456    1
54  Hira    Mansoor     1           2   NULL    2014-02-04  NULL    hiramansoor@gmail.com   0315546464  2
55  Sana    Khan        1           2   NULL    2014-02-04  NULL    sanakhan@gmail.com  2043829429304   3
56  sundus  sundus      1           2   NULL    2014-02-04  NULL    Sunduskhan@hotmail.com  87687678678 1

here depid 2 is computer science and design id 1=supervsior 2=manager 3=senior manager 4=basic user

so when admin login and want to create again account of supervsior and their department is computer sciecne . . now there this is not a logic

beacuse supervsior account with department omputer science already exist so why admin create another supervsior with same department

i use this sp

ALTER procedure [dbo].[spadminreg]
@UserName nvarchar(50),
@Password nvarchar(50),

@UserTypeID int,
@DepID int,
@DesigID int,


@emailaddress nvarchar(50),
@PhoneNumber nvarchar(50)

as
if EXISTS(SELECT 1  from Designation where DesigID=@DepID)
begin
select @DesigID as 'SuperVisor'
end
else if EXISTS (select 2 from Designation where DesigID=@DesigID)
begin
select @DesigID as 'Manager'
end
 else if EXISTS (select 3 from Designation where DesigID=@DesigID)
begin
select @DesigID as 'Senior Manager'
end
 else
insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
values
(@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)

and it works for me

but when i fill textboxes and select same deisgnation with same department like deisgnation 2 and same department 2

then this record not add in table but in .aspx form it show me

"account add succesfully"

and i want to show failed in label

this is code

protected void Btn_SignUp_Click(object sender, EventArgs e)
        {
            try
            {

                c1.SignUp(nametxt.Value, passtxt.Value, Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DropDownList2.SelectedValue),Convert.ToInt32(DropDownList3.SelectedValue),mailtxt.Value,numbtxt.Value);
                //GridView1.DataSource=ca.viewadmin();
                Lbe6.Visible = true;
                 Lbe6.Text = ("Account Successfully Created");
                //  GridView1.DataBind();
            }
            catch
            {
                lbe5.Visible = true;

               lbe5.Text = ("SIGNUP FAILED.PLEASE TRY AGAIN");

            }
            nametxt.Value = "";
            passtxt.Value = "";

            mailtxt.Value = "";
            numbtxt.Value = "";

        }
    }

public void SignUp(string Username, string Password, int UserTypeID, int DepID, int desigid,string emailaddress , string PhoneNumber )
        {
            db.ExecuteNonQuery("spadminreg", new object[] { Username,Password, UserTypeID, DepID,desigid,  emailaddress,PhoneNumber });
        }

please help meee i will very thankful

Recommended Answers

All 3 Replies

hello please help?

You need to check c1.SignUp, to see if the return value is true or false.

Return a result from your stored procedure

ALTER procedure [dbo].[spadminreg]
@UserName nvarchar(50),
@Password nvarchar(50),
@UserTypeID int,
@DepID int,
@DesigID int,
@emailaddress nvarchar(50),
@PhoneNumber nvarchar(50)
as
declare @success int=0
if NOT EXISTS(SELECT *  from Designation where DesigID=@DeigID and DepID=@DepID)
begin
    insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
    values
    (@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)
    set @success=1
end
select @success as result

Your scripts:

public bool SignUp(string Username, string Password, int UserTypeID, int DepID, int desigid,string emailaddress , string PhoneNumber )
        {
           bool result = (bool)db.ExecuteScalar("spadminreg", new object[] { Username,Password, UserTypeID, DepID,desigid,  emailaddress,PhoneNumber });
        }

Your try/catch didn't work because there was no sql error.

protected void Btn_SignUp_Click(object sender, EventArgs e)
        {

            try
            {
                bool success = c1.SignUp(nametxt.Value, passtxt.Value, Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DropDownList2.SelectedValue),Convert.ToInt32(DropDownList3.SelectedValue),mailtxt.Value,numbtxt.Value);
                if(success)
                {
                //GridView1.DataSource=ca.viewadmin();
                Lbe6.Visible = true;
                 Lbe6.Text = ("Account Successfully Created");
                //  GridView1.DataBind();
                }else{
                    lbe5.Visible = true;
                   lbe5.Text = ("SIGNUP FAILED.PLEASE TRY AGAIN");
                nametxt.Value = "";
                passtxt.Value = "";
                mailtxt.Value = "";
                numbtxt.Value = "";
                }
            }
            catch
            {
                lbe5.Visible = true;
                   lbe5.Text = ("Data Execution Error. Debug Necessary");
           }
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.