Microsoft Access: reading datareader values

  • sdekha76 / 102 / Fri, 27 Mar 2009 05:15:00 GMT / Comments (2)
  • I am trying to create an arrayList for each record returned in datareader.. code below:

    //create dtr -- conn.open etc...

    while(dtr.Read())
    {
    ArrayList innerAl = new ArrayList();
    innerAl.Insert(0, dtr["custId"]);
    innerAl.Insert(1, dtr["bookNUMBER"]);

    ....
    outerAl.Add(innerAl);
    }

    I get error "Invalid attempt to read data, when no data is present. why is that?

    SamSad [:(]

  • Keywords:

    reading, datareader, values, microsoft, access

  • http://www.edevs.com/ms-access-database/360/«« Last Thread - Next Thread »»
    1. Not sure... you can probably check for empty data by using the HasRows property prior to entering the loop, but I see no reason why your logic should fail with that particular error. Could it be that you have already called the Read() method once before the loop? If so, that would cause it. Also check to make sure that "custId" and "bookNUMBER" column names are correct and available.

      jcasp | Sat, 05 Jan 2008 10:12:00 GMT |

    2. oh .. I found the error! Always check PostBack..

      sdekha76 | Sat, 05 Jan 2008 10:13:00 GMT |