This tutorial is brought to you by NetroStar, a website development company.
In this tutorial I'll show you the differences between DataSet and Recordset. But in the beginning I'll tell you a few things about Microsoft's technologies used for accessing data sources - ADO and ADO.NET.
ADO and ADO.NET
ADO is ActiveX Data Object that allows you to use data from databases without knowing the implementation of such a database. To access the data programmer even don't have to know SQL although there is a possibility of using SQL commands through ADO as well. One of the main objects in ADO is a Recordset, it will be described in details later in this tutorial. The general idea of using ADO is the following: firstly you have to create and open a connection object that allows you to connect to the database. Then you create a Recordset and retrieve data from the database to it. Afterwards you have the possibility to save potential changes to the database.
ADO.NET is ActiveX Data Object for .NET and it's a successor to ADO.NET although it was changed completely. Its functionalities are similar to the ones from ADO. It allows you to connect to data sources and perform some operations on them. The main object in ADO.NET is Dataset, it's a bit similar to Recordset but it provides more possibilities for developers. ADO.NET makes possible disconnected access to data by taking advantage of XML files.
ADO.NET provides also frameworks that make using databases even simpler. One of them is ADO.NET Entity Framework for object-relational mapping. It presents data from databases as objects and thus makes it much easier to use it by rising level of abstraction. Another framework that is very useful is LINQ (Language Integrated Query), which allow you to query data in a unified and clear way. The main advantage of it is that there exist various providers with which you can query not only databases but also other data sources such as XML, objects or DataSets. If you want to learn more about LINQ check out our previous tutorials.
Here is a list of main differences between ADO and ADO.NET :
- ADO.NET uses disconnected models based on messages whereas ADO is rather connection oriented
- ADO.NET supports XML in an easy and clear way, moreover it uses XML for passing data. On the other hand standard ADO uses binary representation for passing data.
- ADO is based on COM (Component Object Model) and ADO.NET uses CLR (Common Language Runtime)
- Recordset in ADO and DataSet in ADO.NET
DataSet and Recordset
Recordset represents data in memory, usually it's a table or result of a query such as joining two tables or using where clause. At one time there can be only one current record in Recordset, if you want to perform operations on other record you have to use move method. On the other hand DataSet can contain one or more tables from database, these tables are stored in object called DataTable. It is also very easy to retrieve data from it, you can use simple foreach loop to do so. With DataSet you can also maintain relationships between data tables such as for instance foreign key. Generally DataSet can include more rich and complex data and organize it in a clear manner.
As I mentioned before ADO Recordset requires constant connection to database to perform some operations on it while ADO.NET DataSet allows you to make changes and submit all of them to the database later. ADO.NET uses also data adapter which communicates with OLE DB provider while in ADO you communicate with it directly. Data adapters are significant advantage because it's very easy to set up and manage this connection (you can for instance optimize data transfer for performance)
Also performance of DataSets is better because of its architecture, it's faster and more portable than Recordset.
DataSet stores data in XML so it's easier to transfer it to other applications and they are more firewall-prove than Recordsets that are transferred using COM marshalling.
Summing up DataSet is better and more robust tool to manage data from databases and it provides more functionalities. Now I'll show you how you can use DataSet in your applications:
Closing remarks
In this tutorial I showed you the difference between ADO.NET DataSeta and standard ADO Recordset. As you can see on the previous example using DataSet is quite easy. Moreover it has other advantages over old Recordset such as performance, robustness and portability. ADO.NET is a very powerful framework that makes data access easier and more clear and self-explaining.
This tutorial was brought to you by NetroStar, a Miami-based global web design company.