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. The syntax about IDataReader? [modified]

The syntax about IDataReader? [modified]

Scheduled Pinned Locked Moved Visual Basic
databasecsharpquestion
3 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.
  • C Offline
    C Offline
    cateyes99
    wrote on last edited by
    #1

    In the below code snippet, I know it does retrieve value of those specified columns from the Deals table, but look at dataReader("name"), what syntax is this? dataReader is declared as type of interface IDataReader, how can we use it in a way like calling a function? At the first glance, I think it's an overloaded operator - function form "()", but after checking with some documentation, in VB.Net, this operator isn't on the allowed operators list to be overload. So would anyone tell me what syntax is dataReader("name"). Many thanks.

    Imports Microsoft.Practices.EnterpriseLibrary.Data
    Imports Microsoft.Practices.EnterpriseLibrary.Data.Sql

    ...

        Dim lubc As New LookupBaseCollection(GetType(SectypeCommon))
        Dim sqlCommand As String = "SELECT \* From Deals"
        Dim dbCommandWrapper As DBCommandWrapper = Me.database.GetSqlStringCommandWrapper(sqlCommand)
        dbCommandWrapper.CommandTimeout = Me.database.GetConnection().ConnectionTimeout
    
        Dim dataReader As IDataReader = Me.database.ExecuteReader(dbCommandWrapper)
    
        While (dataReader.Read())
            Dim sc As New SectypeCommon(dataReader("transtype").ToString())
            sc.Name = dataReader("name")
            sc.TheKey = dataReader("thekey")
            sc.ShortName = dataReader("code")
            ...
        End While
    

    modified on Wednesday, March 30, 2011 10:16 PM

    T 1 Reply Last reply
    0
    • C cateyes99

      In the below code snippet, I know it does retrieve value of those specified columns from the Deals table, but look at dataReader("name"), what syntax is this? dataReader is declared as type of interface IDataReader, how can we use it in a way like calling a function? At the first glance, I think it's an overloaded operator - function form "()", but after checking with some documentation, in VB.Net, this operator isn't on the allowed operators list to be overload. So would anyone tell me what syntax is dataReader("name"). Many thanks.

      Imports Microsoft.Practices.EnterpriseLibrary.Data
      Imports Microsoft.Practices.EnterpriseLibrary.Data.Sql

      ...

          Dim lubc As New LookupBaseCollection(GetType(SectypeCommon))
          Dim sqlCommand As String = "SELECT \* From Deals"
          Dim dbCommandWrapper As DBCommandWrapper = Me.database.GetSqlStringCommandWrapper(sqlCommand)
          dbCommandWrapper.CommandTimeout = Me.database.GetConnection().ConnectionTimeout
      
          Dim dataReader As IDataReader = Me.database.ExecuteReader(dbCommandWrapper)
      
          While (dataReader.Read())
              Dim sc As New SectypeCommon(dataReader("transtype").ToString())
              sc.Name = dataReader("name")
              sc.TheKey = dataReader("thekey")
              sc.ShortName = dataReader("code")
              ...
          End While
      

      modified on Wednesday, March 30, 2011 10:16 PM

      T Offline
      T Offline
      TwoFaced
      wrote on last edited by
      #2

      dataReader("name") is the short version of dataReader.Item("name"). You can do this because the property 'Item' is the default property.

      C 1 Reply Last reply
      0
      • T TwoFaced

        dataReader("name") is the short version of dataReader.Item("name"). You can do this because the property 'Item' is the default property.

        C Offline
        C Offline
        cateyes99
        wrote on last edited by
        #3

        Thanks very much. I didn't know that before.

        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