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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:17+00:00 2026-05-26T22:47:17+00:00

I am writing a query to allow a user to search on what they

  • 0

I am writing a query to allow a user to search on what they provide keywords in asp.net, C# and mssql:

 string projectPart = null;
 string categoryPart = null;
 string descriptionPart = null;

 if (this.Textbox_ProjectNr.Text.Trim().Length > 0)
   projectPart = " AND Number='" + this.Textbox_ProjectNr.Text.Trim() + "' ";

 if (this.Textbox_Category.Text.Trim().Length > 0)
   categoryPart = " AND Category LIKE '%" + this.Textbox_Category.Text.Trim() + "%' ";

 if (this.Textbox_pDescription.Text.Trim().Length > 0)
    descriptionPart = " AND ProductDescription LIKE '%" + this.Textbox_pDescription.Text.Trim() + "%' ";

 string query = "SELECT * from Project  = p.ID " + projectPart + descriptionPart + categoryPart;

I dont know whether this query is sufficient for a traditional query search. Because I see there are some bottlenecks of this search:

  1. if the user does not type anything, it returns all of the data => For this I only do the query when one of the fields are filled.
  2. if the user provides some keywords “P” for each field, the result will be millions of data.

I dont know how to improve the search query basically. any suggestions are appreciated.

Thanks in adavance.

  • 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-26T22:47:18+00:00Added an answer on May 26, 2026 at 10:47 pm

    The most important improvement is to protect you code against SQL injection attacks.

    You should not concatenate the raw input in the SQL string. If someone searches for the following text for example:

    Bwah ha ha'; DROP DATABASE northwind; PRINT'
    

    This will be added to your query to produce

    SELECT *
    FROM mytable
    WHERE category LIKE '%Bwah ha ha'; DROP DATABASE northwind; PRINT'%'
    

    This is a valid SQL command and will happily execute and drop your database (or do anything else the attacker wants)

    For more information see SQL Injection and Santitizng Inputs.

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

Sidebar

Related Questions

I'm writing a query that inserts customer data into a MSSQL database. Very basic.
I am writing an application that allows a user to submit a query to
I'm writing a web app, with Codeigniter, that allows a user to enter query
I'm writing a php-mysql application. The application allows the user to run a search
I'm writing a script in PHP to allow a user to change their password.
I'm writing an user-driven app with several zones to it. I want to allow
I am having trouble writing query so that I can query the content of
When writing a query for paging on a web page what is the least
I'm writing this query and I'm running into a mental road block. I keep
I am writing the query to count the number of distinct values in the

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.