Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem in datatable class select function with special characters

Problem in datatable class select function with special characters

Scheduled Pinned Locked Moved C#
helpregex
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abcurl
    wrote on last edited by
    #1

    I am facing a problem while filtering using the datatable class select function. Following is the code.

    DataTable dt;
    DataRow dr ;

    dt = New DataTable()
    dt.Columns.Add("t", System.Type.GetType("System.String"));
    dr = dt.NewRow();
    dr["t"] = "12";
    dt.Rows.Add(dr);

    Dim search As String

    'There is no problem when i write the following search string

    search = "~!@#$%^&*"

    dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");

    but problem comes when i append a special character ( with the search

    search = "~!@#$%^&*(";

    dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");

    Error message is Error in Like operator: the string pattern '%~!@#$[%]^&*(%' is invalid.

    A 1 Reply Last reply
    0
    • A abcurl

      I am facing a problem while filtering using the datatable class select function. Following is the code.

      DataTable dt;
      DataRow dr ;

      dt = New DataTable()
      dt.Columns.Add("t", System.Type.GetType("System.String"));
      dr = dt.NewRow();
      dr["t"] = "12";
      dt.Rows.Add(dr);

      Dim search As String

      'There is no problem when i write the following search string

      search = "~!@#$%^&*"

      dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");

      but problem comes when i append a special character ( with the search

      search = "~!@#$%^&*(";

      dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");

      Error message is Error in Like operator: the string pattern '%~!@#$[%]^&*(%' is invalid.

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      abcurl wrote:

      search = "~!@#$%^&*(";

      Try search=@"~!@#$%^&*(";

      Me, I'm dishonest. And a dishonest man you can always trust to be dishonest.
      Honestly. It's the honest ones you want to watch out for...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups