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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:37:45+00:00 2026-05-11T11:37:45+00:00

Greetings, I have two questions regarding a DataTable.Select(): 1) How to escape potential apostrophes

  • 0

Greetings,

I have two questions regarding a DataTable.Select():

1) How to escape potential apostrophes or any other characters that would cause an issue. I’m not worried about SQL Injection. 2) How to use IN with Like, and include results that have a null.

1) Unfortunately, I can’t seem to find any advice for the first option since every one says use parametrized (is that a word) queries which I’m pretty sure you can’t do with the Datatable.select. The situation is like so, I don’t know what the values are going to be ahead of time since the list is retrieved from a textbox. (‘US’ , ‘Engineering’ , ‘Lumburg’s’) I know I could parse the string before passing it to the select but I’m sure there is some ANSI built in away of doing it which I’m afraid I don’t know. I’m aware that two apostrophes in a row would escape the character if I knew where it was going to be located but I don’t know the exact location when I receive it.

2) Ok. Now for the actual Select Expression. What I’m looking to do is allow the user to free form type into a text field. This text field will use 4 different columns to filter by. So the user could type in several items separated by space which would then perform a query per their criteria. (like the iTunes search box which allows you to type free form album song etc or you could be specific and only search by one type of item)

I know how to do an IN or a Like by themselves but I’m not sure how I could put them together (including escaping the apostrophes and including results that match but might have a null in one of the columns) and of course do something that is supported by the .Select method.

WHERE (Country IN (‘US’ , ‘Engineering’ , ‘Lumburg’s’)) WHERE (Country LIKE ‘LU%’)

So the user in the case above provided LU which should return a record for Lumburg. The more information they provide would further refine the results. Any ideas?

Here is the technical specs regarding my application:

Winforms VB.NET .Net 2.0

  • 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. 2026-05-11T11:37:45+00:00Added an answer on May 11, 2026 at 11:37 am

    You’ll want to end up with a query that looks like:

    Country = ‘US’ OR Country = ‘Engineering’ OR Country = ‘Lumburg”s’ OR Country LIKE ‘LU%’

    terms = //split apart their search entry foreach (string searchTerm in terms) {   // I don't know how you're telling the difference between terms you want an exact   // match for, and which use like, but do something like this    if (exactMatchNeeded)   {     query += ' OR Country = '' + searchTerm.Replace(''', '''') + '' ';   }   else   {     query += ' OR Country LIKE '' + searchTerm.Replace(''', '''') + '' ';   } } 

    Of course you’ll need to tidy that up to make sure of some things like preventing the extra ‘OR’ on the beginning, but this should get you started.

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

Sidebar

Related Questions

Greetings, I've got a query that I'm struggling with, this is the first time
Greetings. I have some inputs dynamically added to form. <input name=input_names[] /> When form
Greetings, I would like to detect if a segment only 'touches' a polygon or
Greeting, I have two levels of authentications in ASP.NET application. I have a Webadmin
Greeting, if I have asp.net checkboxlist control : <asp:CheckBoxList id=list1 runat=server> <asp:ListItem>One</asp:ListItem> <asp:ListItem>Two</asp:ListItem> <asp:ListItem>Three</asp:ListItem>
I want to model an activity, where there can be two several initiating events.
Greetings all, I use MinGW,QT and CMake for my project. As shown in the
Greetings all, I'm working with a C# solution in VS 2010. Right now, since
Greeting, I listed two examples of using style propriety for asp.net control. what is
I am currently working through Accelerated C++ and have come across an issue in

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.