none
DataTableReader is invalid for current DataTable

    Question

  • I'm trying to convert a datatable into a datatablereader but i'm getting this error

    DataTableReader is invalid for current DataTable

    does everyboth nows about it ??

    i'm running the simple command "

    mydatatable.GetChanges(DataRowState.Added)

    "

     

    Monday, October 30, 2006 2:19 PM

Answers

  • I found the problem !!!
    I forgot the method Reader.Read();

    tks everyone

    Monday, October 30, 2006 5:04 PM
  • DataTableReader does provide a reader interface over a DataTable without needing a connection.  The method to obtain the reader is DataTable.CreateDataReader().

    The error you are seeing is thrown by the reader when the current row the reader is positioned on is not present or is invalid.  This can happen if you make changes to the DataTable after obtaining the reader.  It may also happen if you have no rows in the table when you call CreateDataReader() (I haven't actually tested this scenario, just a quick glance at the code).
    Monday, October 30, 2006 4:43 PM
  • here is my situation...

    I have to apply a filter....
    Then i'm doing this...

    DataTable blah = MyDataTable.Clone();
    blah.ImportRow(MyDataRow);
    blah.AcceptChanges();
    DataTableReader Reader = blah.CreateDataReader();

    When the method CreateDataReader is called the exception comes on my screen...

    I'm lost...

    Could you help me ?

     

     

    Monday, October 30, 2006 4:59 PM

All replies

  • Hi,

    this is the definition from the msdn for the getChanges method

    Gets a copy of the DataSet that contains all changes made to it since it was loaded or since AcceptChanges was last called.

    Basically, it is fullfilled with only the changes that were done in the DataSet, in your case, where the RowState property of the columns is Added., so you can not get a DataReader from a Table using this method.

    Then, remember that a DataReader is a connected object, so it needs a connection for working. so, you can not convert something is disconnected like a dataset and its datatables in a connected object.

    What do you want to do ?

     

    Best Regards

     

    Monday, October 30, 2006 3:38 PM
  • DataTableReader does provide a reader interface over a DataTable without needing a connection.  The method to obtain the reader is DataTable.CreateDataReader().

    The error you are seeing is thrown by the reader when the current row the reader is positioned on is not present or is invalid.  This can happen if you make changes to the DataTable after obtaining the reader.  It may also happen if you have no rows in the table when you call CreateDataReader() (I haven't actually tested this scenario, just a quick glance at the code).
    Monday, October 30, 2006 4:43 PM
  • here is my situation...

    I have to apply a filter....
    Then i'm doing this...

    DataTable blah = MyDataTable.Clone();
    blah.ImportRow(MyDataRow);
    blah.AcceptChanges();
    DataTableReader Reader = blah.CreateDataReader();

    When the method CreateDataReader is called the exception comes on my screen...

    I'm lost...

    Could you help me ?

     

     

    Monday, October 30, 2006 4:59 PM
  • I found the problem !!!
    I forgot the method Reader.Read();

    tks everyone

    Monday, October 30, 2006 5:04 PM
  • Thankyou.. I forgot the exact same thing! Surprise)

    Thursday, August 23, 2007 2:33 PM
  • same here.

    I forgot

    while (oDataReader.Read())

    and when I added it, it worked.
    Wednesday, March 26, 2008 4:45 PM