The syntax about IDataReader? [modified]
-
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 isdataReader("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
-
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 isdataReader("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
-
dataReader("name") is the short version of dataReader.Item("name"). You can do this because the property 'Item' is the default property.