Datareader, there is no data...

Discussion in 'ASP .Net' started by Arjen, Jul 30, 2003.

  1. Arjen

    Arjen Guest

    Hello,

    How can I check the recordcount?

    Here is a little bit of my code:
    // Load first row into Datareader
    dr.Read();

    if (dr["Category"].ToString() == "xmlsrc") {

    When I do this I get an error because there is no data... it only have to
    check this dr["Category"].ToString() == "xmlsrc") if there is data.
    How can I do that?

    Thanks!
     
    Arjen, Jul 30, 2003
    #1
    1. Advertising

  2. Arjen

    Arjen Guest

    When I search for your best practice with google.com I don't find al lot of
    material.

    http://www.google.nl/search?hl=nl&ie=UTF-8&oe=UTF-8&q=ColumnEnum&lr=

    What namespace do I have to use for ColumnEnum?

    Thanks!



    "PJ" <> schreef in bericht
    news:#...
    > the .Read() method returns false if it has reached the end of it's record
    > stream so your code should be
    >
    > if ( dr.Read() )
    > {
    > //perform actions on row
    > }
    >
    > and...btw, use enums rather than strings to access your columns...it's
    > quicker
    >
    > if ( (string)dr[Convert.ToInt32(ColumnEnum.Category)] == "xmlsrc" )
    > //...
    >
    > "Arjen" <> wrote in message
    > news:bg7ufi$mro$1.nb.home.nl...
    > > Hello,
    > >
    > > How can I check the recordcount?
    > >
    > > Here is a little bit of my code:
    > > // Load first row into Datareader
    > > dr.Read();
    > >
    > > if (dr["Category"].ToString() == "xmlsrc") {
    > >
    > > When I do this I get an error because there is no data... it only have

    to
    > > check this dr["Category"].ToString() == "xmlsrc") if there is data.
    > > How can I do that?
    > >
    > > Thanks!
    > >
    > >

    >
    >
     
    Arjen, Jul 30, 2003
    #2
    1. Advertising

  3. Arjen

    PJ Guest

    ColumnEnum was just an example of an enum you would create to access the
    columns in your SqlDataReader

    enum ColumnEnum
    {
    Id, Category, etc
    }

    this way you are accessing the columns by their int index, rather than their
    name, which is obviously faster.

    "Arjen" <> wrote in message
    news:bg834s$62h$1.nb.home.nl...
    > When I search for your best practice with google.com I don't find al lot

    of
    > material.
    >
    > http://www.google.nl/search?hl=nl&ie=UTF-8&oe=UTF-8&q=ColumnEnum&lr=
    >
    > What namespace do I have to use for ColumnEnum?
    >
    > Thanks!
    >
    >
    >
    > "PJ" <> schreef in bericht
    > news:#...
    > > the .Read() method returns false if it has reached the end of it's

    record
    > > stream so your code should be
    > >
    > > if ( dr.Read() )
    > > {
    > > //perform actions on row
    > > }
    > >
    > > and...btw, use enums rather than strings to access your columns...it's
    > > quicker
    > >
    > > if ( (string)dr[Convert.ToInt32(ColumnEnum.Category)] == "xmlsrc" )
    > > //...
    > >
    > > "Arjen" <> wrote in message
    > > news:bg7ufi$mro$1.nb.home.nl...
    > > > Hello,
    > > >
    > > > How can I check the recordcount?
    > > >
    > > > Here is a little bit of my code:
    > > > // Load first row into Datareader
    > > > dr.Read();
    > > >
    > > > if (dr["Category"].ToString() == "xmlsrc") {
    > > >
    > > > When I do this I get an error because there is no data... it only have

    > to
    > > > check this dr["Category"].ToString() == "xmlsrc") if there is data.
    > > > How can I do that?
    > > >
    > > > Thanks!
    > > >
    > > >

    > >
    > >

    >
    >
     
    PJ, Jul 30, 2003
    #3
    1. Advertising

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. James Brown
    Replies:
    1
    Views:
    5,461
    bruce barker
    Jun 26, 2003
  2. Kivanç Karaca

    DataReader Error When there is no record!

    Kivanç Karaca, Oct 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,259
    Mark Rae
    Oct 13, 2004
  3. =?Utf-8?B?R3JhbnQ=?=
    Replies:
    2
    Views:
    969
    Joanna
    Sep 13, 2006
  4. Rob Nicholson
    Replies:
    15
    Views:
    20,511
    Rob Nicholson
    Sep 24, 2005
  5. Jeremy.Chen
    Replies:
    2
    Views:
    368
    Jeremy.Chen
    Jan 6, 2009
Loading...

Share This Page