i have a admin users.. when once admin supervisor added by admin and set designation supervisor and department as computer science .. then when again admin add account and try to add admin and set his designation supervisor and department computer science then here i want to show error " designation already exist" ..because every department has one supervisor , one manager and also one senior manager ....not multiple supervisors ,managers i try this sp and code.. sp
ALTER procedure [dbo].[spadmindesig]
@DesigID int
as
if exists(select * from Designation where DesigID=@DesigID)
return -1
else
return 1
and for admin signup
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
if exists(select * from Designation where DesigID=@DesigID)
return -1
else
return 1
insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
values
(@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)
code
public void AdminSignUp(string Username, string Password, int UserTypeID, int DepID, int desigid, string emailaddress, string PhoneNumber)
{
db.ExecuteScalar("spadminreg", new object[] { Username, Password, UserTypeID, DepID, desigid, emailaddress, PhoneNumber });
}
public string Admindes( int desigid)
{
string val=db.ExecuteScalar("spadmindesig", new object[] { desigid }).ToString();
return val;
}
button code
protected void Btn_SignUp_Click(object sender, EventArgs e)
{
try
{
//test
//value = adminsignup.Admindes(Convert.ToInt32(DropDownList2.SelectedValue));
string val= adminsignup.Admindes(Convert.ToInt32(DropDownList2.SelectedValue));
if(val=="1")
{
adminsignup.AdminSignUp(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 = ("Designation Already Exists.");
// GridView1.DataBind();
}
else
{
lbe5.Visible = true;
lbe5.Text = ("");
}
}
catch
{
lbe5.Visible = true;
lbe5.Text = ("SIGNUP FAILED.PLEASE TRY AGAIN");
}
nametxt.Value = "";
passtxt.Value = "";
mailtxt.Value = "";
numbtxt.Value = "";
}
supervisor account exist in table and when i add supervisor account and set same designation and department then it show me error "signup failed " and i want to display error " designation already exist" and when i delete existing supervisor account from table and then again i add supervisor account then it shows me error ..
object reference not set to an instance of an object