does SqlDataReader inherit from IEnumerator : yes or no ???

  • Thread starter Thread starter Christian
  • Start date Start date
C

Christian

Hi,

the browser in Vis.Studio .NET indicates that SqlDataReader inherits from
IEnumerator, but intellisense doesn't show any member (GetEnumerator) of an
SqlDataReader object.

Nor does the following compile :
SqlCommand cmd = new SqlCommand("SELECT firstname, lastname, city FROM
employees");
SqlDataReader myReader = cmd.ExecuteReader();
myReader.GetEnumerator();
==> ERROR : 'System.Data.SqlClient.SqlDataReader' does not contain a
definition for
'GetEnumerator'

IEnumerator myEnum = myReader as IEnumerator;
=> ERROR : Cannot convert type 'System.Data.SqlClient.SqlDataReader' to
'System.Collections.IEnumerator' via a built-in
conversion

So why is the browser showing it in the hierarchy chart ?

thnx

chris
 
You don't need enumerator.

you can use while loop to get your data

while (myReader.Read())
{
myReader.GetValue(ColumnNameorColumnIndex)

}
 
Hi Chris,

SqlDataReader implements IEnumerable and don't implement IEnumerator.
Usualy both of interfaces implemented to support foreach close etc.,
but not in this case.

Base regards,
Leon
 
Back
Top