locked
DataTable.Load RRS feed

  • Question

  • I have a SQLDataReader that contains 11 rows

    When loading the data table as follows

    DataTable.Load(SQLDataReader)

    It only loads 10 rows. What happened to Number 11? i.e. the first row is missing.

    when looping through the DataReader and using DataTable.LoadDataRow({c1, c2, c3, ...}, false)

    I get all 11 rows.

    What gives here? I'm hoping I will not have to go through all of my code and replace the table loads.

    Framework is .NET 4


    Lee


    • Edited by Lee Taylor Friday, April 12, 2013 7:49 PM
    Friday, April 12, 2013 7:47 PM

Answers

All replies

  • This post explains the behaviour

    http://stackoverflow.com/questions/229425/net-datatable-skips-rows-on-loaddatareader

    Instead use a Dataadapter to load the datatable the way you want


    Abhinav
    http://bishtabhinav.wordpress.com/


    • Edited by AB82 Saturday, April 13, 2013 1:25 AM
    • Proposed as answer by Mike Feng Wednesday, April 17, 2013 11:04 AM
    • Marked as answer by Mike Feng Tuesday, April 23, 2013 3:07 PM
    • Unmarked as answer by Lee Taylor Tuesday, April 23, 2013 5:05 PM
    • Marked as answer by Lee Taylor Tuesday, April 23, 2013 5:05 PM
    Saturday, April 13, 2013 1:24 AM
  • Check yoiur connection string to see if HDR is set to Yes or No.  Normally the default is yes.  If you data has no header then the first row is being intepreted as the header row.

    jdweng

    • Proposed as answer by Mike Feng Wednesday, April 17, 2013 11:04 AM
    • Marked as answer by Mike Feng Tuesday, April 23, 2013 3:07 PM
    • Unmarked as answer by Lee Taylor Tuesday, April 23, 2013 5:04 PM
    • Unproposed as answer by Lee Taylor Tuesday, April 23, 2013 5:05 PM
    Saturday, April 13, 2013 12:08 PM