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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:43:51+00:00 2026-06-16T07:43:51+00:00

Recently, I am doing filtering in the datatable via DataView in following way: public

  • 0

Recently, I am doing filtering in the datatable via DataView in following way:

        public static DataTable FilterDatatable(this DataTable dtable,string @operator, string colName, string colValue)
        {
            if (dtable != null && dtable.Rows.Count > 0)
            {
                DataView dataView = dtable.DefaultView;

                if (@operator.Equals(SqlOperator.Like , StringComparison.InvariantCultureIgnoreCase))
                {
                    dataView.RowFilter = colName + " " + @operator + " '%" + colValue + "%'";
                }
                else
                {
                    dataView.RowFilter = colName + " " + @operator + " " + colValue;
                }

                return dataView.ToTable();
            }
            return dtable;
        }

Here, I can write a method for preventing injection(those injection I know) but indeed, I don’t know the best way to prevent the injection in the datatable just like sql paramater.

Above method throws exception when I send single quote appended string as a argument in ColVal….

  • 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-16T07:43:52+00:00Added an answer on June 16, 2026 at 7:43 am

    You don’t need protection in that instance – DataTable.Select() is applying a filter to the DataRows held in-memory within that DataTable, it’s not actually connecting to/executing anything against the database.

    UPDATE

    how about creating this method to double any single instance of single quote

    private string MethodName(string str)
    {
        return str.Replace("'", "''");
    }
    

    so to use,

    dataView.RowFilter = colName + " " + @operator + " '%" + MethodName(colValue) + "%'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing some pagination recently and used the following: if ( $totalPages >
Sorry about the confusing title. I recently started doing this in my project, and
I want to select recently created element doing something like this: $(body).append(<div id='popup.dialog'></div>); dialogDiv
This is something I have been doing recently and was wondering if others do
I'm doing on this template recently. The background images works fine in all browsers
I've recently seen several people doing things like this here on Stackoverflow: class A:
I've recently seen several people doing things like this here on Stackoverflow: class A:
Recently while doing some work with C# & ActiveMQ (via the Apache.NMS libraryies) I
I've noticed a few sites doing this recently and I'm pretty sure I've come
I've recently been doing a lot of Objective-C programming, and just got back into

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.