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 8994753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:30:04+00:00 2026-06-15T23:30:04+00:00

I am a new ASP.NET developer and I am developing a web-based application in

  • 0

I am a new ASP.NET developer and I am developing a web-based application in which there is a menu bar that has many options. Some of these options will be displayed only to the Admin. There is a logic behind the system to check whether the user is an admin or not. If yes, the options will be displayed. I wrote the method but I have a sql injectiom and I want to remove it.

For your information, I have the following database design:

  • Users table: NetID, Name, Title
  • Admins table: ID, NetID

Here’s the C# method:

private bool isAdmin(string username)
{
        string connString = "Data Source=appSever\\sqlexpress;Initial Catalog=TestDB;Integrated Security=True";
        string cmdText = "SELECT ID, NetID FROM dbo.Admins WHERE NetID = '" + NetID + "')";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            // Open DB connection.
            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                    if (reader.Read())
                        if (reader["ID"].Equals(1))
                            return true;
                return false;
            }
        }
    }

I tried to change it by doing the changing the third line to:

string cmdText = "SELECT ID, NetID FROM dbo.Admins WHERE NetID = @NetID)";

But I got the following error and I don’t know why:

Must declare the scalar variable “@NetID”.

Could you please help me in solving this?

**UPDATE:

After updating the code to the following:
    private bool isAdmin(string username)
    {
        string NetID = username;
        string connString = "Data Source=appServer\\sqlexpress;Initial Catalog=TestDB;Integrated Security=True";
        string cmdText = "SELECT ID, NetID FROM dbo.Admins WHERE NetID = @NetID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            // Open DB connection.
            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                cmd.Parameters.AddWithValue("@NetID", NetID);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                    if (reader.Read())
                        if (reader["NetID"] == username)
                            return true;
                return false;
            }
        }
    }

I got the following error:

Incorrect syntax near ‘)’.

How to fix this problem?

  • 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-15T23:30:05+00:00Added an answer on June 15, 2026 at 11:30 pm

    Try this

     private bool isAdmin(string username)
     {
        string connString = "Data Source=appSever\\sqlexpress;Initial Catalog=TestDB;Integrated Security=True";
        string cmdText = "SELECT ID, NetID FROM dbo.Admins WHERE NetID = @NetID)";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            // Open DB connection.
            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                cmd.Parameters.AddWithValue("@NetID", NetID);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                    if (reader.Read())
                        if (reader["ID"].Equals(1))
                            return true;
                return false;
            }
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new ASP.NET developer and I am developing a web-based suggestions box
I'm developing a web application using asp.net. There is a text box which contains
I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
New ASP.NET Web API HttpClient has been giving me some strange results. Here is
I am building a new asp.net MVC3 web application for reporting and I want
I'm developing a plugin based application using MEF and Asp.NET MVC 3 and I
I am part of a development team building a new ASP.NET 3.5 web application.
Using ASP.Net Am New to website development Currently am developing a web pages, when
I am developing an asp.net web services. I am new to asp.net but I
I am a new ASP.NET developer and I am developing a traning management system

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.