Datareader design not generic

E

Edward Diener

I would have expected an IDataReader to be able to return an IDataRecord
from some interface function for the current row, to allow one to fetch the
row and its values generically. But I did not find such functionality. Did I
miss it ? Why is IDataReader not designed as generically as the other ADO
..NET interfaces ?
 
M

Miha Markic [MVP C#]

Hi Edward,

If you look at classes that implement IDataReader, you'll see that they also
implement IDataRecord.
 
E

Edward Diener

Miha Markic said:
Hi Edward,

If you look at classes that implement IDataReader, you'll see that they
also implement IDataRecord.

But classes which implement IDataReader are not generic. They are specific
to a particular implementation such as Oracle, SqlServer, OleDb, or Odbc.
That was my entire point of asking why IDataReader does not have a function
which returns an IDataRecord. Then implementation classes which implement
IDataReader could return their own version of IDataRecord. This would make
the IDataReader generic rather than specific to an implementation since
IDataRecord is generic enough to be used, as is, to return column values.
Nearly all other interfaces in ADO .NET can be treated generically in such a
way, with only a very small amount of implementation specific functionality
added for classes which implement the interface. Only IDataReader, among the
major interfaces, can not. One simply can not use IDataReader to get a row,
and therefore the values of the columns of that row, without using instead a
specific class which implements it.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Edward Diener said:
I would have expected an IDataReader to be able to return an IDataRecord
from some interface function for the current row, to allow one to fetch
the row and its values generically. But I did not find such functionality.
Did I miss it ? Why is IDataReader not designed as generically as the
other ADO .NET interfaces ?
 
S

Sahil Malik

Edward,

The generic is Odbc/OleDb. Although being generic it is upto 70% slower.

What is the specific business case in which you are running into this
"limitation". Not every ado functionality is a one to one map between ado
and ado.net. I'd like to know what you are trying to acheive in ADO, that
you are having problem achieving in ADO.NET.


- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik



Edward Diener said:
Miha Markic said:
Hi Edward,

If you look at classes that implement IDataReader, you'll see that they
also implement IDataRecord.

But classes which implement IDataReader are not generic. They are specific
to a particular implementation such as Oracle, SqlServer, OleDb, or Odbc.
That was my entire point of asking why IDataReader does not have a function
which returns an IDataRecord. Then implementation classes which implement
IDataReader could return their own version of IDataRecord. This would make
the IDataReader generic rather than specific to an implementation since
IDataRecord is generic enough to be used, as is, to return column values.
Nearly all other interfaces in ADO .NET can be treated generically in such a
way, with only a very small amount of implementation specific functionality
added for classes which implement the interface. Only IDataReader, among the
major interfaces, can not. One simply can not use IDataReader to get a row,
and therefore the values of the columns of that row, without using instead a
specific class which implements it.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Edward Diener said:
I would have expected an IDataReader to be able to return an IDataRecord
from some interface function for the current row, to allow one to fetch
the row and its values generically. But I did not find such functionality.
Did I miss it ? Why is IDataReader not designed as generically as the
other ADO .NET interfaces ?
 
B

bruce barker

it is generic. that what the IDataReader and IDataRecord intefaces are for.

IDataReader dr = createADataReader();
while (dr.read)
{
for (i=0; i<dr.FieldCount; ++i)
{

Console.Write(string.format("{0}={1}\n",dr.GetName(i),dr.GetValue(i));
}
}
dr.Close();

this code will work with any datareader the function creates
(SQL,OBDC,Oracle,etc). any Implementation of IDataReader must also implement
the IDataRecord inteface.

-- bruce (sqlwork.com)



| I would have expected an IDataReader to be able to return an IDataRecord
| from some interface function for the current row, to allow one to fetch
the
| row and its values generically. But I did not find such functionality. Did
I
| miss it ? Why is IDataReader not designed as generically as the other ADO
| .NET interfaces ?
|
|
 
E

Edward Diener

bruce said:
it is generic. that what the IDataReader and IDataRecord intefaces
are for.

IDataReader dr = createADataReader();
while (dr.read)
{
for (i=0; i<dr.FieldCount; ++i)
{

Console.Write(string.format("{0}={1}\n",dr.GetName(i),dr.GetValue(i));

It is my mistake. I know see that IDataReader implements IDataRecord. You
are correct that it is generic and my missing the fact that it implements
IDataRecord caused me to miss it.
}
}
dr.Close();

this code will work with any datareader the function creates
(SQL,OBDC,Oracle,etc). any Implementation of IDataReader must also
implement the IDataRecord inteface.

Yes, you have said exactly what I missed here. I was looking under the list
of IDataReader members in MSDN
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfsystemdataidatareadermemberstopic.asp) and only saw the ones which are
directly part of IDataReader. I noticed that for .NET classes, when one is
viewing all members, that both those which are public and protected in the
particular class and those which are public and protected in base classes
are listed. Evidently this is not the case for .NET interfaces in the MSDN
documentation, where only those which are in the particular interface are
listed and not those in base interfaces, and that is what confused me more
than anything. Because of that I had not taken a good look at the line which
shows the interface declaration itself, which lists the implemented
interfaces. Thanks for the reply !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top