Datareader design not generic

Discussion in 'Microsoft ADO .NET' started by Edward Diener, Dec 10, 2004.

  1. 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 ?
     
    Edward Diener, Dec 10, 2004
    #1
    1. Advertisements

  2. Hi Edward,

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

    --
    Miha Markic [MVP C#] - RightHand .NET consulting & development
    SLODUG - Slovene Developer Users Group
    www.rthand.com

    "Edward Diener" <> wrote in message
    news:...
    >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 ?
    >
     
    Miha Markic [MVP C#], Dec 10, 2004
    #2
    1. Advertisements

  3. "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    >>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 ?
    >>

    >
    >
     
    Edward Diener, Dec 10, 2004
    #3
  4. Edward Diener

    Sahil Malik Guest

    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" <> wrote in message
    news:e5sHh#...
    > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
    > news:%...
    > > 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" <> wrote in message
    > > news:...
    > >>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 ?
    > >>

    > >
    > >

    >
    >
     
    Sahil Malik, Dec 10, 2004
    #4
  5. Edward Diener

    bruce barker Guest

    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)



    "Edward Diener" <> wrote in message
    news:...
    | 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 ?
    |
    |
     
    bruce barker, Dec 10, 2004
    #5
  6. bruce barker wrote:
    > 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 !

    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    > "Edward Diener" <> wrote in message
    > news:...
    >> 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 ?
     
    Edward Diener, Dec 10, 2004
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michelle Stone

    DataReader, hardcoding column number. why not col name?

    Michelle Stone, Sep 20, 2003, in forum: Microsoft ADO .NET
    Replies:
    2
    Views:
    357
    William Ryan
    Sep 20, 2003
  2. Le Fletan
    Replies:
    2
    Views:
    312
    Le Fletan
    Sep 24, 2003
  3. Robert Phillips

    Not getting SqlException using DataReader

    Robert Phillips, Sep 29, 2003, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    309
    Robert Phillips
    Sep 30, 2003
  4. Peter Stojkovic

    Datareader and Getint32 does not work

    Peter Stojkovic, Dec 4, 2003, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    698
    Miha Markic
    Dec 9, 2003
  5. Radostin Gerchev

    Generic Data Access design problems

    Radostin Gerchev, Jun 8, 2004, in forum: Microsoft ADO .NET
    Replies:
    6
    Views:
    366
    =?ISO-8859-1?Q?Fredrik_=C5lund?=
    Jun 10, 2004
Loading...

Share This Page