Dealing With DataViews

I never liked being forced to use DataView just to speed up my searches. Why not DataTable.Select() have an overload to generate internal indexes and do some smart things? But anyway, most people searching DataSet eventually would realizes that performance really sucks and they have no choice but to use DataViews, sometime whole bunch of it prepared for all sorts of queries you want to fire. Here are two things you should watch out (MSDN docs aren’t clear about this):

  1. If you call myDataView(someIndex).Delete anywhere in your code, watch out that you do not access any other rows with index > someIndex. If you do, you might either get a run time error or even worse, you might be accessing row underneath that’s different then you actually wanted without any error. Another corollary: Never delete rows in DataView in forward loop.

  2. If you are changing/adding row in DataTable or other DataViews, do not forget to call row.BeginEdit and row.EndEdit. If you don’t, your changes will not appear in other views you have.

Well, performance gains through DataView is still pretty sweet thing to have 🙂

Avatar
Shital Shah

A program trying to understand what it’s computing.

comments powered by Disqus