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. Visual Basic
  4. .NET DataTable Search

.NET DataTable Search

Scheduled Pinned Locked Moved Visual Basic
questioncsharp
7 Posts 3 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.
  • N Offline
    N Offline
    nlindley7
    wrote on last edited by
    #1

    I need to be able to search a DataTable for a non-primary key field. I'd assume the best way is just to populate a dataset and fill the table. But how do I search the table for non-primary key values? Nathan Lindley .NET Aficionado

    M Z 2 Replies Last reply
    0
    • N nlindley7

      I need to be able to search a DataTable for a non-primary key field. I'd assume the best way is just to populate a dataset and fill the table. But how do I search the table for non-primary key values? Nathan Lindley .NET Aficionado

      M Offline
      M Offline
      mr_lasseter
      wrote on last edited by
      #2

      Something along the lines of for each datarow in datatable if datarow.coumn(i) = searchvalue then return what you want end if next

      Mike Lasseter

      N 1 Reply Last reply
      0
      • M mr_lasseter

        Something along the lines of for each datarow in datatable if datarow.coumn(i) = searchvalue then return what you want end if next

        Mike Lasseter

        N Offline
        N Offline
        nlindley7
        wrote on last edited by
        #3

        I had played around with iterating the DataTable for the row, but was unsuccessful. I guess i'll play around with it a little more. Thanks. Nathan Lindley .NET Aficionado

        1 Reply Last reply
        0
        • N nlindley7

          I need to be able to search a DataTable for a non-primary key field. I'd assume the best way is just to populate a dataset and fill the table. But how do I search the table for non-primary key values? Nathan Lindley .NET Aficionado

          Z Offline
          Z Offline
          zacharyshroyer
          wrote on last edited by
          #4

          Dim dr() as DataRow dr = datatable.Select("FieldName = 'something'") dr will be an array of rows from the datatable that match the query.

          N 1 Reply Last reply
          0
          • Z zacharyshroyer

            Dim dr() as DataRow dr = datatable.Select("FieldName = 'something'") dr will be an array of rows from the datatable that match the query.

            N Offline
            N Offline
            nlindley7
            wrote on last edited by
            #5

            You can't assign a dataRow to an Array of datarows...i think the error says something like '1 dimensional array System.Data.DataRow cannot be converted to System.Data.DataRow' ... thanks for the response though. :-D Nathan Lindley .NET Aficionado

            Z 1 Reply Last reply
            0
            • N nlindley7

              You can't assign a dataRow to an Array of datarows...i think the error says something like '1 dimensional array System.Data.DataRow cannot be converted to System.Data.DataRow' ... thanks for the response though. :-D Nathan Lindley .NET Aficionado

              Z Offline
              Z Offline
              zacharyshroyer
              wrote on last edited by
              #6

              It works. I've used it many times. You must declare the DataRow variable as an array. **use the parentheses after the name of the variable** Dim dr() As DataRow The select function of the DataTable class will return an array of data row objects. I am using .NET 2005

              N 1 Reply Last reply
              0
              • Z zacharyshroyer

                It works. I've used it many times. You must declare the DataRow variable as an array. **use the parentheses after the name of the variable** Dim dr() As DataRow The select function of the DataTable class will return an array of data row objects. I am using .NET 2005

                N Offline
                N Offline
                nlindley7
                wrote on last edited by
                #7

                Good call with the casting it as a DataRow array. Nathan Lindley .NET Aficionado

                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