Click here to Skip to main content
15,905,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HEY
i have a adim users.. when once adim 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


code

C#
protected void Btn_SignUp_Click(object sender, EventArgs e)
        {


       
  public void SignUp(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 });

        }
Posted
Updated 24-Feb-14 2:30am
v4
Comments
Ahmed Bensaid 18-Feb-14 10:37am    
Why don't you answer questions from CodeProject users ... ?
http://www.codeproject.com/Questions/723626/download-link-in-pending-status
Diya Ayesa 18-Feb-14 11:10am    
oh sorry ... the link u provide and ur answer works for me ...thanku
Ahmed Bensaid 18-Feb-14 11:38am    
Ok. Therefore, accept my solution, so the thread will appear as "Solved" ... Thanks
Diya Ayesa 18-Feb-14 11:56am    
so can u please tell me this question is there any solution
Ahmed Bensaid 18-Feb-14 12:16pm    
My day's work is over ... I'll try to help you when I'll be at home ;)

1 solution

Make little bit change in your posted code.

SQL
ALTER procedure [dbo].[spadminreg]
@UserName nvarchar(50),
@Password nvarchar(50),
@UserTypeID int,
@DepID int,
@DesigID int,
@emailaddress nvarchar(50),
@PhoneNumber nvarchar(50),
@action nvarchar(50)
 
AS
BEGIN
 
if(@action='CheckDuplicate')
  BEGIN
    Select count(*) from Userss where UserTypeID=@UserTypeID AND DepID=@DepID And DesigID=@DesigID;
  END
if(@action='Insert')
  BEGIN
   insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
    values
   (@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)
   END
   end
GO



& in c# code ..
C#
public void AdminSignUp(string Username, string Password, int UserTypeID, int DepID, int desigid, string emailaddress, string PhoneNumber)
        {
            try{
//--before using this part check proper return type for your execute scalar metod & then try to convert it to int so that you can get count of duplicate rows
      int count=  Convert.toInt32(  db.ExecuteScalar("spadminreg", new object[] { Username, Password, UserTypeID, DepID, desigid, emailaddress, PhoneNumber ,"CheckDuplicate"}));

        if(count>0)
            {
    // Duplicate entries are present
             }
          else
           {
     //Insert into data base.
         }
            }
 
 
      catch(Exception)
    {
 
     }
        }
 
Share this answer
 
Comments
Please don't post multiple answers to the same question. Instead Improve the first one.
V5709 20-Feb-14 0:18am    
:)
Please delete this.
V5709 20-Feb-14 2:32am    
Fine boss :)
Good. :) Nobody is boss here :P There is only one boss looking everybody.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900