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. Using 'Like' in DataTable select query

Using 'Like' in DataTable select query

Scheduled Pinned Locked Moved C#
databasealgorithms
7 Posts 6 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.
  • K Offline
    K Offline
    kanchoette
    wrote on last edited by
    #1

    I have a datatable which I wish to search for 'Like' matches. So searching for "p" would bring up the entries "p1", "Pea green", "p3" etc. I have code DataRow[] foundRows; foundRows = debtorDataSet.Tables["AutoText"].Select("Code LIKE " + lastWord + "%" ); if (foundRows.Length == 1) { .... } else { .... } but this is not working. Any pointers much appreciated.

    L P 2 Replies Last reply
    0
    • K kanchoette

      I have a datatable which I wish to search for 'Like' matches. So searching for "p" would bring up the entries "p1", "Pea green", "p3" etc. I have code DataRow[] foundRows; foundRows = debtorDataSet.Tables["AutoText"].Select("Code LIKE " + lastWord + "%" ); if (foundRows.Length == 1) { .... } else { .... } but this is not working. Any pointers much appreciated.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      as it is a string literal you are using, your statement seems to be missing some quotes, try this:

      ...Select("Code LIKE '" + lastWord + "%'" );

      :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      K R U 3 Replies Last reply
      0
      • L Luc Pattyn

        as it is a string literal you are using, your statement seems to be missing some quotes, try this:

        ...Select("Code LIKE '" + lastWord + "%'" );

        :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        K Offline
        K Offline
        kanchoette
        wrote on last edited by
        #3

        Many thanks.

        1 Reply Last reply
        0
        • K kanchoette

          I have a datatable which I wish to search for 'Like' matches. So searching for "p" would bring up the entries "p1", "Pea green", "p3" etc. I have code DataRow[] foundRows; foundRows = debtorDataSet.Tables["AutoText"].Select("Code LIKE " + lastWord + "%" ); if (foundRows.Length == 1) { .... } else { .... } but this is not working. Any pointers much appreciated.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Luc's already given you the information you need, but I'd like to suggest that you should also look at using string.Format rather than explicit string concatenation - sometimes it just makes it easier to read. So, you'd end up with something like string.Format("code like '{0}%'", lastWord);

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          1 Reply Last reply
          0
          • L Luc Pattyn

            as it is a string literal you are using, your statement seems to be missing some quotes, try this:

            ...Select("Code LIKE '" + lastWord + "%'" );

            :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            R Offline
            R Offline
            rishimuni
            wrote on last edited by
            #5

            ;)

            1 Reply Last reply
            0
            • L Luc Pattyn

              as it is a string literal you are using, your statement seems to be missing some quotes, try this:

              ...Select("Code LIKE '" + lastWord + "%'" );

              :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


              U Offline
              U Offline
              User 13689356
              wrote on last edited by
              #6

              If column name is (FIRST NAME) If I use as Select("FIRST NAME LIKE '" + lastWord + "%'" ); It shows error

              J 1 Reply Last reply
              0
              • U User 13689356

                If column name is (FIRST NAME) If I use as Select("FIRST NAME LIKE '" + lastWord + "%'" ); It shows error

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                It is a bad idea to post a question to a more than four years old thread. Most users here will not even see it. If you got an error message, add the full message text to your question. That helps others to help you. However, your column name contains a space. Then you have to enclose it in brackets:

                Select("[FIRST NAME] LIKE '" + lastWord + "%'" );

                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