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. DataTable.Select() finding data in all columns...

DataTable.Select() finding data in all columns...

Scheduled Pinned Locked Moved C#
questionregex
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.
  • T Offline
    T Offline
    thecodedemon
    wrote on last edited by
    #1

    I'm trying to search a DataTable, with .Select(), to find all rows with a certain string in any of the columns.I basically want to match a string *string* with the data in any of the columns in a particular table. I've tried, simply, table.Select( "'*' LIKE '*" + searchTerm + "*'" ) and while that runs with no errors, it also returns nothing. Had one idea, it's selecting fom all columns, but all columns do not have the sarchTerm, thus nothing returns. How can I tell it to return rows where ANY column has the searchTerm, while not excluding because the other columns do not have the searchTerm?

    A soft glow comes from the pit in the darkness. The clicking noise become faster - and louder. A wind begins to stir up from the pit, as the creature flexes it's wings, preparing for flight. You stare into the pit, and hear a voice say in your mind, "If you survive the encounter, declare it to the world." The Code Demon Rises.

    C 1 Reply Last reply
    0
    • T thecodedemon

      I'm trying to search a DataTable, with .Select(), to find all rows with a certain string in any of the columns.I basically want to match a string *string* with the data in any of the columns in a particular table. I've tried, simply, table.Select( "'*' LIKE '*" + searchTerm + "*'" ) and while that runs with no errors, it also returns nothing. Had one idea, it's selecting fom all columns, but all columns do not have the sarchTerm, thus nothing returns. How can I tell it to return rows where ANY column has the searchTerm, while not excluding because the other columns do not have the searchTerm?

      A soft glow comes from the pit in the darkness. The clicking noise become faster - and louder. A wind begins to stir up from the pit, as the creature flexes it's wings, preparing for flight. You stare into the pit, and hear a voice say in your mind, "If you survive the encounter, declare it to the world." The Code Demon Rises.

      C Offline
      C Offline
      CKnig
      wrote on last edited by
      #2

      First: the wildchar '*' in SQL is '%' Second: you will have to provide the names of the columns (yes for all) with OR between - for example: DataRow[] Rows = table.Select(string.Format( "'Name LIKE '%{0}%' OR Phone LIKE '%{0}%'", searchTerm) );

      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