throw ArgumentOutOfRangeException when add new row RRS feed

  • Question

  • Hi all

    I have a problem, when i call method Add (MyDataSet.DTProject.Rows.Add(row)) in DataRowCollection, i got an exception the ArgumentOutOfRangeException.

    Message summary:  Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    StackTrace:    at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Collections.Generic.List`1.RemoveAt(Int32 index)
       at System.Data.RecordManager.NewRecordBase()
       at System.Data.DataTable.NewRecord(Int32 sourceRecord)
       at System.Data.DataRow.BeginEditInternal()
       at System.Data.DataRow.set_Item(DataColumn column, Object value)

    Friday, June 5, 2015 3:00 AM

All replies

  • Can you show a little more of your code?

    ~~Bonnie DeWitt [C# MVP]


    Sunday, June 7, 2015 4:04 PM
  • Also, if this is a Typed DataSet (which is what it looks like from the code you've posted), it would be better to use and add the Typed Row, like this:

    MyTypedDataSet.DTProjectRow row = MyDataSet.DTProject.NewDTProjectRow();
    // set the columns in row:
    // row.x = this; row.y = that; ... etc.

    ~~Bonnie DeWitt [C# MVP]


    • Proposed as answer by Fred Bao Monday, June 8, 2015 3:01 AM
    Sunday, June 7, 2015 4:28 PM