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

  • Home
  • SEARCH
  • 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 8614815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:12:46+00:00 2026-06-12T05:12:46+00:00

Iam a little bit Confused for my HR Application I had three type of

  • 0

Iam a little bit Confused for my HR Application I had three type of Users

1) Normal User(location based user) , assigned type U

2) Administrator(company based) , assigned type A

3) Management assigned type M

My problem is in forms DATAGRIDVIEW normal user(HR) should get the employee details of his location(branch) only while the Administrator should get the whole employee details the company company and the Management should get the whole emp details of all their group of companies

I have almost 56 forms where Ia m Calling select query to get data like

 SqlCommand cmd = new SqlCommand("Select * from EMPMASTERTBL" ,CON);
            cmd.Parameters.AddWithValue("@Param1", empshiftdata.Empid);

BUT MY REQUIREMENT IS

For normal user

(if program.usertype="n"){
 SqlCommand cmd = new SqlCommand("Select * from EMPMASTERTBL where branchlctn=@Param1",CON);
                cmd.Parameters.AddWithValue("@Param1", program.lctnpk);

}

for management

(if program.usertype="M"){
     SqlCommand cmd = new SqlCommand("Select * from EMPMASTERTBL",CON);

or

    }

But it is not posible to call three different sql queries in each function
So Is there any idea to concat the two queries?
like

SqlCommand cmd = new SqlCommand("Select * from EMPMASTERTBL where branchlctn=@Param1",CON);
                   cmd.Parameters.AddWithValue("@Param1", program.lctnpk);//for normal user
                    cmd.Parameters.AddWithValue("@Param1", "*");//for Management  user
  • 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-12T05:12:48+00:00Added an answer on June 12, 2026 at 5:12 am

    Why not create the command variable before the conditions, then set the query itself and parameters within the conditions?

    // TODO: Improve your naming, which is unconventional and includes odd
    // abbreviations ("lctnpk"?)
    SqlCommand command = new SqlCommand { Connection = CON };
    if (program.usertype=="n") {
        command.CommandText = "Select * from EMPMASTERTBL where branchlctn=@Param1";
        command.Parameters.AddWithValue("@Param1", program.lctnpk);
    } else if (program.usertype == "M") {
        command.CommandText = "Select * from EMPMASTERTBL";
    }
    

    Alternatively, you could have two parameters, always:

    SqlCommand command = new SqlCommand(
        "Select * from EMPMASTERTBL where branchlctn=@Param1 or @usertype='M'" CON);
    command.Parameters.AddWithValue("@Param1", program.lctnpk);
    command.Parameters.AddWithValue("@usertype", program.usertype);
    

    … and let the query optimizer work out what’s going on. I’d be slightly nervous of this solution – it would quite possibly want different query plans for the different cases; fundamentally you’re executing different queries, so it probably makes sense to reflect that in your SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i am little bit confused in valu type or referance type... for instance
I am little bit confused about creating universal application for iOS devices using Xcode
I am little bit confused about this statement that I read in a book
I am little bit confused about following problem & their solutions: i have 2
I am a little bit confused about 2 things. Firstly when I create an
I am a little bit confused on something, see I am doing an Ajax
I am a little bit confused by the PHP function declare . What exactly
I am a little bit confused with Doctrine class. I created a class and
--I haven't develop any iPhone Web Application ever...so i am little bit confuse about
I am little bit confused of that what happened because it's illogical for me.

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.