datatable.select raises error for non-indexed fields

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
 
N

Norman Yuan

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top