Friday, October 22, 2004

DataSets - the fog clears

Well, I've been using datasets since I started using .NET about 3.5 years ago, but in the past few days I've learnt a few new things that I thought I'd share with you.

Datasets are not stored internally as xml. I guess I had always assumed that they were, probably for a couple of reasons. One; I think someone told me this early in my .NET experience; and Two, datasets handle xml so well it almost seems like a logical conclusion. Suffice it to say, I was wrong, and you can find out all the details
here.

Another point of dataset enlightenment I had is this:
Databinder.Eval is bad! Apparently ( and I must admit I haven't written any tests to prove this, although it does make sense ) using Databinder.Eval is about 20% slower than using explicit casting. This is because Databinder.Eval uses reflection to figure out what the type of the object in the container is that you are trying to display. So instead of doing something like this:

<%# Databinder.Eval(Container.DataItem, "MyItem") %>

you should do something like this:

<%# ((DataRowView)Container.DataItem)["MyItem"] %>

however if you do this, you will also need to add this line

<%@ Import Namespace="System.Data"%>

to the top of your html page , otherwise you will get the following error at runtime:

Compiler Error Message: CS0246: The type or namespace name 'DataRowView' could not be found (are you missing a using directive or an assembly reference?

You can find out more about this here.

0 Comments:

Post a Comment

<< Home