datatable.select raises error for non-indexed fields

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi,

mydatatable.select("IsDeleted = 0") is raising this error:
Run-time exception thrown :
System.IndexOutOfRangeException - Index was outside the
bounds of the array.

mydatatable.select("OutlineEntryID = '" & myID.ToString
& "'") works fine, where myID is a GUID. The only
difference I can see is that OutlineEntryID is the
primary key, and IsDeleted is just a normal field in the
datatable.

does datatable.Select only work for indexed fields?

Thanks,
David
 
I'd guess there is nothing wrong with mydatatable.select("IsDaleted=0")
itself. Probably it is how you use its returned value. DataTable.Select()
returns a DataRow array: if no DataRow found in that table, the array is
empty (Length=0). This is the place where "System.IndexOutOfRangeException"
could happen. For example if you do:

DataRow dr=myTable.Select("IsDelete=0")[0]
//You though there at least one row can be found,
//while actually no datarow meets that selection creterion,
//then you get "IndexOutOfRangeException"
 
Back
Top