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 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 all, I have a wxPython project (created with wxFormBuilder) that contains two panels,
I am wondering how you would approach this problem I have two Taxrates that
Greetings I have a program that creates multiples instances of a class, runs the
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings, I have some mysql tables that are currently using an md5 hash as
Greetings, Any input on a way to divide a std::vector into two equal parts
Greetings, Basically, I have two vectors of data (let's call it experimental and baseline).
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
Greetings- I have 2 classes. One is called Programs and the other is called
Greetings Overflow users, I created a series of custom ComboBox controls, that should have

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.