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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:47+00:00 2026-05-23T13:44:47+00:00

Problem: I have a form with text values, and a function that must return

  • 0

Problem: I have a form with text values, and a function that must return a string query based on the values of the text values too.

Solution: I created a SQLCommand query with parameters, then I put the SQLCommand.CommandText to a string and I returned it (to the business logic that is going to handle the query)

Main Question: Is it sql-injection proof?

Code Example:

sQuery = "select * from xy where x like '%@txtNameParameter%'";

SqlCommand cmd = new SqlCommand(sQuery);

cmd.Parameters.Add("@txtNameParameter", SqlDbType.VarChar);
cmd.Parameters["@txtNameParameter"].Value = txtName.Text;

string query = cmd.CommandText;
return query;

Sub question if main question is ok:
Should I put into parameters also values of a radiobutton and dropdownmenu or are they injection-proof?

  • 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-05-23T13:44:47+00:00Added an answer on May 23, 2026 at 1:44 pm

    What you are doing here is injection proof because you are not injecting anything. In fact, your parameter isn’t even used (because the only reference to it is inside a string literal so the SQL Parser won’t even see where you are attempting to use the parameter because it will treat it as a string literal.)

    You may want to change that line of code to:

    sQuery = "select * from xy where x like '%'+@txtNameParameter+'%'";
    

    Which would make the SQL look like this:

    select * from xy where x like '%'+@txtNameParameter+'%'
    

    Which is just string concatenation in a place where a string is expected in the SQL command anyway.

    However, your description of what you are doing with this afterwards possibly blows all that out of the water. I cannot understand why you would want to send just the where clause of the query to the business layer.

    Also, the substringed WHERE clause will not contain the data you are putting in the parameter. So you are getting no more benefit that just returning

    return "where x like '%@txtNameParameter%'";
    

    The parameter value is lost.

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

Sidebar

Related Questions

I have problem with TinyMCE editor. I have form with few text fields and
I have a problem. The client is claiming that a prize signup form I
I have an InfoPath form with several fields on, the problem is that one
The problem I am encountering is that for my login form I have to
I have a small problem with jQuery $.ajax() function. I have a form where
I am using the jQuery form validation plugin. The problem I have is that
I have a big form, that will be serialized by a jQuery function. The
I have the following problem: I have a form in site/banen (currently local running
so here's the problem I have one form, it outputs search results after submit,
I have problem in declaring the intents on my app. I have a form

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.