Datareader, there is no data...

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Datareader, there is no data...

    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 Guest

  2. Similar Questions and Discussions

    1. Datareader, Datagrid and hyperlinks
      I am filling a datareader and then assigning the reader to the datagrid as follows: SqlDataReader reader = ADOConnect.populateDatareader();...
    2. DG-Edit-Loosing data; bound columns - pushbuttons; dataReader
      Dear Readers, I am using C# (vb examples will work for me too - i am vb progrmr). I created a dg (datagrid) with bound columns (hesistant to...
    3. need an example of running conditions against data in a DataReader.
      Could someone post an example of conditional evaluation of a data from a database using the dataReader class that builds a new row if a field is not...
    4. datareader.getstring(0) error
      Hi, my code is very simple. dim cm as oledbcommand= new oledbcommand("select * from page " ,cn) cn.open() Dim dr As OleDbDataReader =...
    5. can't getstring & display datareader
      Hi, I want to display a single record datareader and get a value from it. But I can't do both together. After "dim dr as...
  3. #2

    Default Re: Datareader, there is no data...

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

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

    What namespace do I have to use for ColumnEnum?

    Thanks!



    "PJ" <pjwalNOSPAM@hotmail.com> schreef in bericht
    news:#VjCicnVDHA.2040@TK2MSFTNGP10.phx.gbl...
    > 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" <boah123@hotmail.com> wrote in message
    > news:bg7ufi$mro$1@news4.tilbu1.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 Guest

  4. #3

    Default Re: Datareader, there is no data...

    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" <boah123@hotmail.com> wrote in message
    news:bg834s$62h$1@news2.tilbu1.nb.home.nl...
    > When I search for your best practice with google.com I don't find al lot
    of
    > material.
    >
    > [url]http://www.google.nl/search?hl=nl&ie=UTF-8&oe=UTF-8&q=ColumnEnum&lr=[/url]
    >
    > What namespace do I have to use for ColumnEnum?
    >
    > Thanks!
    >
    >
    >
    > "PJ" <pjwalNOSPAM@hotmail.com> schreef in bericht
    > news:#VjCicnVDHA.2040@TK2MSFTNGP10.phx.gbl...
    > > 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" <boah123@hotmail.com> wrote in message
    > > news:bg7ufi$mro$1@news4.tilbu1.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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139