Aviel Lazar

Aviel Lazar

  • NA
  • 1
  • 0

System.IndexOutOfRangeException: Cannot find column N

Jan 4 2006 7:45 AM
Hello,
I'm writing a web application and I'm using a strong typed dataset with 2 additional calculated columns.
Before updating with the dataAdpater I'm removing the calculated columns to avoid an Exception of the strong typed dataset:
//..Code..//
//Removing the caculated columns
foreach (DataColumn dc in strongTypedDT.Columns)
{
if (dc.Expression!="")
{
dataTable.Columns.Remove(dc);
}
}

try
{
da.Update(strongTypedDS.strongTypedDT);

strongTypedDS.strongTypedDT.AcceptChanges();
}

catch(Exception e)
{
throw e;
}
}
//..Code..//

After that,I'm adding the calculated columns back.
Everything worked fine until I used a DataView which is sorted by one of the caculated columns(which were removed and returned again), on some WebForm.This form works fine, it shows the data sorted.

//..Code..//

DataView dv= new DataView((DataTable)Session["strongTypedDT"]);
dv.Sort="calClmn";

//..Code..//

On the WebForm which tries to update the dataset(shared by session) using the code above. The "da.Update(strongTypedDS.strongTypedDT);" throws the following excpetion:"System.IndexOutOfRangeException: Cannot find column 8."
I tried to remove the sorting expression and everything worked fine again.
Any suggestions?
Thank you in advance :)

P.S

StackTrace:
at System.Data.DataColumnCollection.get_Item(Int32 index)
at System.Data.Index.CompareRecords(Int32 record1, Int32 record2)
at System.Data.Index.GetIndex(Int32 record)
at System.Data.Index.RecordChanged(Int32 record)
at System.Data.DataTable.RecordChanged(Int32 record)
at System.Data.DataRow.RowErrorChanged()
at System.Data.DataRow.set_RowError(String value)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)