DataTable has lots of cool features!!
Many of us proabably haven't used the coolest features provided in DataTable. I was also unknown to its features previously. I came across this features one day, when i just roaming in search engines.
Some features, I like most are listed below.
1. I can directly load the SqlDataReader by using the load method of datatable. So I don't need to use data adapter any more.
e.g. DataTable dt = new DataTable();
dt.Load(sqlDataReader);
2. It can be used directly as a datasource as well. e.g. dt.CreateDataReader();
3. It has functions like ReadXML, WriteXML, ReadXmlSchema, WriteXmlSchema...to work with XML file directly.
4. I can use FindBy<Primarykey> method to get the particular data row.
e.g ProductDataRow dr = dt.FindByProductID(proID); //search
5. I even can select filtered datarows.. sort by fieldname.
e.g. DataRows[] rows= dt.Select("Price>100", "ProductName");//filter and sort
6. I even can compute sum, average...without iterating datatable.
e.g. decimal totalAmount = dt.Compute("Sum(ProductPrice)",String.Empty);//sum
Ya...very nice features.
These are most common functions I use and there are lots more...They are type safe, and has user friendly functionalities like sorting, filtering, searching etc. I really enjoy using these functionalities of Typed dataset and datatable provided by ADO.NET.