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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. datareader

datareader

Scheduled Pinned Locked Moved ASP.NET
databasehelp
4 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.
  • A Offline
    A Offline
    amaneet
    wrote on last edited by
    #1

    Sir, I was trying to retrieve some data from the database , It is successfully retrieved. The problem is , there are two terms and i don't know the difference between them. 1.dr.Item(0) or dr.item("columnnmane") 2.dr.GetValue(dr.GetOrdinal("columnname")) Please explain the difference , I mean in which condition i should use dr.Item("") or dr.Item(0) and In which condiion I should use dr.GetValue(dr.GetOrdinal("columnname")) Thanks

    J G 2 Replies Last reply
    0
    • A amaneet

      Sir, I was trying to retrieve some data from the database , It is successfully retrieved. The problem is , there are two terms and i don't know the difference between them. 1.dr.Item(0) or dr.item("columnnmane") 2.dr.GetValue(dr.GetOrdinal("columnname")) Please explain the difference , I mean in which condition i should use dr.Item("") or dr.Item(0) and In which condiion I should use dr.GetValue(dr.GetOrdinal("columnname")) Thanks

      J Offline
      J Offline
      Jim Conigliaro
      wrote on last edited by
      #2

      It is usually a best practice to reference your data by column name, so the dr.Item([ColumnName]) method is best. The reasoning behind this is that if your query changes and you add or remove columns, you won't need to modify the your code to adjust for the resulting changes in column indexes. The GetOrdinal method returns the index of a column that can then be used to retrieve the data for the specified column. This method is often used if performance is a concern. Retrieving data by column index is faster than by nane, so if you are looping through a large number of columns, you will typically retrieve the column index by name using the GetOrdinal method and then use that index to retrieve the data.

      Jim Conigliaro jconigliaro@ieee.org
      http://www.jimconigliaro.com

      1 Reply Last reply
      0
      • A amaneet

        Sir, I was trying to retrieve some data from the database , It is successfully retrieved. The problem is , there are two terms and i don't know the difference between them. 1.dr.Item(0) or dr.item("columnnmane") 2.dr.GetValue(dr.GetOrdinal("columnname")) Please explain the difference , I mean in which condition i should use dr.Item("") or dr.Item(0) and In which condiion I should use dr.GetValue(dr.GetOrdinal("columnname")) Thanks

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        dr.Item(0) and dr.GetValue(0) are the same. dr.Item("columnname") and dr.GetValue(dr.GetOrdinal("columnname")) are the same.

        --- b { font-weight: normal; }

        A 1 Reply Last reply
        0
        • G Guffa

          dr.Item(0) and dr.GetValue(0) are the same. dr.Item("columnname") and dr.GetValue(dr.GetOrdinal("columnname")) are the same.

          --- b { font-weight: normal; }

          A Offline
          A Offline
          amaneet
          wrote on last edited by
          #4

          Sir, I just wanted to know he difference between them. Thanks

          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