Ido Samuelson

Notes, thoughts and exceptions

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910


Navigation

Blogs I read

Articles

My WorkSpaces

Subscriptions

News

Only 10 kind of people in the world. Those who understand binary and those who don't.

Post Categories

Article Categories



Wednesday, April 13, 2005 - Posts

DataSet tips

Although am not a big fan of Datasets, Datasets are the core Entities in several projects am working on.

I encounter over and over again, specially in IT projects how Dataset are being used without being aware what is happening behind the scene. I decided to write some tips on how to use them...

for each DataTable in a DataSet there is a boolean property named Enforceconstraints. This property means that it will Enforce the constraints of your data to make sure the data is valid via it's schema. Which means that if I use the DataAdapter to fill a curtein Table, the enforce constrains will make sure the data is valid. This leads me to tip #1

TIP #1 Enforceconstraints= false when you fill your DataTable. This will improve your loading performance. (you should Enforceconstraints= True after Fill completed)

Another 2 important methods that I keep reminind the server side developers is to make use of the very important 2 methods of a DataTable. BeginLoadData() and EndLoadData(). If you aren't using those two methods now, you should go back and fix your code.

TIP #2 Make sure you ALWAYS use BeginLoadData() before you load data to a DataTable. The reason is that BeginLoadData() simply turn off notification, index maintenance, and constrains while loading data.

TIP #3 Make sure you ALWAYS use EndLoadData() after data was loaded to a DataTable. To simply turn on notification, index maintenance, and constrains.

The last 2 tips are more familier to developers, but mainly because it's being used by the CurrencyManager in DataBinding... In  DataRow object there are 2 methods that should be used when you want to make a change to more then one column in a row. BeginEdit() and EndEdit().

TIP #4 While Updating more then 1 column in a DataRow, call BeginEdit() before you change the values. Events are temporarily suspended allowing the user to make multiple changes to more than one row without triggering validation rulesIn

TIP #5 After updating the values of a DataRow, call EndEdit() to accept the updates.  Events will be enabled again. EndEdit() method is called implicitly when you invoke the DataTable object's AcceptChanges() method.

Futhermore, I strongly suggest to read the MSDN comments regarding these functions, it will sure improve your coding skills.

posted Wednesday, April 13, 2005 7:25 PM by snick




Powered by Dot Net Junkies, by Telligent Systems