Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:45:20+00:00 2026-06-15T18:45:20+00:00

I have an intranet web-based application that stores the information of added users in

  • 0

I have an intranet web-based application that stores the information of added users in its database.

What I want to do is the following: when the user browses to the webstie, it will check if the user exists in its own database or not. If not, it is going to check his information using Active Directory.

I wrote the method but the problem after checking the database and if the user is not there, it will go to the second method which is checking the organization code of the employee:

public static bool isMember(string userid)
{
        Employee employee = new Employee(userid);

        if (!String.IsNullOrEmpty(userid))
        {
            string username = userid;
            string connString = "Data Source=appServer\\sqlexpress;Initial Catalog=dbTest;Integrated Security=True";
            string cmdText2 = "SELECT Count(*) FROM employee WHERE Username = @username";

            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                // Open DB connection.
                using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
                {
                    cmd.Parameters.Add("@Username", SqlDbType.VarChar);
                    cmd.Parameters["@username"].Value = username;
                    var count = (int)cmd.ExecuteScalar();
                    return count == 1; // return true if there's only one employee with given name
                }
            }
        }
        else if (employee.department.Code == "30003143") //The SapCode of department is "30003143"
            return true;
        else
            return false;
    }

So how to fix that? How to make the application goes through (else if) clause if the user does not exist in the database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:45:20+00:00Added an answer on June 15, 2026 at 6:45 pm

    Pretty easy:

    public static bool isMember(string userid)
    {
        // guard clause - if "userid" is invalid, return "false" right away 
        if (String.IsNullOrEmpty(userid))
        {
            return false
        }
    
        //Object from Employee class
        Employee employee = new Employee(userid);
    
        string username = userid;
        string connString = "Data Source=appServer\\sqlexpress;Initial Catalog=dbTest;Integrated Security=True";
        string cmdText2 = "SELECT Count(*) FROM employee WHERE Username = @username";
    
        using (SqlConnection conn = new SqlConnection(connString))
        using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
        {
                cmd.Parameters.Add("@Username", SqlDbType.VarChar);
                cmd.Parameters["@username"].Value = username;
    
                conn.Open();
    
                var count = (int)cmd.ExecuteScalar();
    
                if (count == 1)
                {
                   return true; // return true if there's only one employee with given name
                }
        }
    
        // if the user already existed in the database - then the above RETURN has 
        // returned "true" to the caller. So these lines are **only** executed if the
        // user was NOT found in the database.
    
        if (employee.department.Code == "30003143") //The SapCode of department is "30003143"
            return true;
    
        // now check in Active Directory here.....     
        return UserExistsInActiveDirectory();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me share the following scenario: I have a ASP.NET intranet Web-based application that
I need to develop a mailing system in the intranet web-based application that I
I'd like to gather user data in a web-based intranet application similar to rapportive
I have written a MVC web application that is used on our corporate intranet.
I am developing a small intranet based web application. I have YSlow installed and
I have an intranet application that needs contact information for various locations on our
I have created some PHP-based intranet resources that require users to log in. The
I have a web (intranet) tool that parses a users list into an array
I have a legacy intranet web app that was written for IE7 and contains
I have a custom navigation menu for my SharePoint intranet web application which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.