ASP.NET - difference between type dataset and non-type dataset

Asked By aman on 09-Aug-11 02:31 AM
hi all,

what is the difference between Type dataset and Non-type dataset?
how to do practical demonstration of the same?

thanks and regards
Aman Khan
Ravi S replied to aman on 09-Aug-11 02:35 AM

Dataset : the dataset can be defined as collection of tables which resides in client as inmemory storage.

This can be classifides into two types

1.untyped dataset: the dataset which follows the unstructure is called as Unstructured dataset.

Ex : dim ds as new dataset();

2.Typed Dataset: typed dataset can be inherited from dataset class by providing strongly typed properties and methods.

typed Dataset: Structure+strongly typed properties and methods.

Ravi S replied to aman on 09-Aug-11 02:37 AM

Untyped DataSets

Untyped datasets are hard to maintain since the developer has to know the in depth details of the database. This scenario is not practical since in actual programming the developer does not have any idea of the database layer and its hidden from him by the database administrators.

Another disadvantage of using Untyped DataSets is that the code looks hideous. Consider the code below which simply retrieves the first row of the first column from the database.

// Weak Type DataSet

DataSet weakDataSet = new DataSet();


string articleId = weakDataSet.Tables["Articles"].Rows[0][0].ToString();

I am simply make a dataset object and filling the dataset using SqlDataAdapter. Once the dataset is loaded with data I am retrieving the first row of the first column in the dataset. As you can see that by just looking at the code to retrieve the data one cannot simply understand that what is going to be returned.   

Now if you are using a dataset and need to print all the rows than you might have to code something like this:

foreach(DataTable dt in weakDataSet.Tables)


foreach(DataRow dr in dt.Rows)


foreach(DataColumn dc in dt.Columns)






As you can see the code above is hard to understand since we have not mentioned any column in the database. Although it will work fine but its very hard to understand that what is going on.

Most of these problems are solved by using Strongly Typed DataSets. Let's see how we can use them.

Strongly Typed DataSets:

You can start using Strongly Typed DataSets by simply adding a new dataset item from right clicking the project and selecting add new item. Later you can drag and drop a table from the server explorer to create a Strongly Typed DataSets.

Once you have created Typed DataSet you can simply make an object of that dataset and than you are ready to use it.

Below I made an instance of the typed dataset "MyDataSet".

MyDataSet ds = new MyDataSet();

Once the DataSet is created we need to fill it using SqlDataAdapter.


Now let's see that how easy it is to refer to the column and rows that are present in the dataset.




As you can see above that now we know that which columns we are referring to. The Articles is the name of the table and [0] represents the first row of the column ArticleID, Author and DateCreated.

Now let's see how we can iterate through the dataset.

foreach(MyDataSet.ArticlesRow articleRow in ds.Articles)




 As you see that now we don't have to type much code in order to iterate through the dataset. We just used the dataset row to iterate through the dataset collection and finally we added the items in the Listbox.

Typed DataSets are more faster than the UnTyped DataSets. Strongly typed datasets are early bound and their columns represents the properties. Also that if you are getting errors in Typed DataSets they will most probably be compile time and not runtime so you can always fix them.

when you make Typed DataSets you also get some extra features and methods that are very useful.


As you can see above each column that is included in the Typed DataSet comes with a method which let's the user know that if the current row that he is accessing is null or not. This is very convenient for columns that can have null values. If you don't check for null values "Object reference not set to an instance" error will be fired.

Adding new columns in the Typed DataSets are also very easy. Just switch back to the xsd schema graphical user interface and add the column.

Now after adding a new column just build the application and you are ready to use the new column.

The coolest feature of using Typed DataSets is that you can convert the whole dataset schema into a class which can be used by other users. You can easily do this by using a tool called XSD.exe.

Go to the Visual Studio.NET Command prompt. And type this command.

xsd MyDataSet.xsd /c

The /c in the end means that we are creating a class file from the xsd file. There are many things you can do depending on the type of the escape sequence you apply.

Remember that this command must be run from the same directory where the xsd file is present. Once you the command it will create the class file with the same name as that of the xsd file.

Now you schema has become portable and so others can easily use this.

Many people are using Typed DataSets as business objects. There are some problems in this approach which I will address in my future article "Typed DataSets Vs Entity Classes".

I hope you enjoyed the article, happy programming !


dipa ahuja replied to aman on 09-Aug-11 03:00 AM
Datasets can be typed or untyped. A typed dataset is a dataset that is first derived from the base DataSet class and then uses information in an XML Schema file (an .xsd file) to generate a new class. Information from the schema (tables, columns, and so on) is generated and compiled into this new dataset class as a set of first-class objects and properties.


You can use either type of dataset in your applications. However, Visual Studio has more tool support for typed datasets, and they make programming with the dataset easier and less error-prone. 

Anoop S replied to aman on 09-Aug-11 03:32 AM
A DataSet can be Typed or Untyped. The difference between  the two lies in the fact that a Typed DataSet has a schema  and an Untyped DataSet does not have one. It should be noted that the Typed Datasets have more support in Visual  studio.Typed Dataset provide compile time type checking. Also it  provides the names of the Columns of the types we are using for that typed data set. This is something we dont get in  the normal datasets.
Jitendra Faye replied to aman on 09-Aug-11 04:14 AM

Typed Dataset (TDS):

TDS is added using MS VS as .xsd file by right clicking solution and clicking ‘Add New Item’ and by selecting DataSet. We can also generate TDS using xsd.exe, a VS .NET command prompt tool. TDS is easy to use. TDS is also called as strongly typed dataset because we get compile time errors in case there is any type (datatype) mismatch. Strongly TDS is slow in terms of performance. It is used only in small applications.

Untyped Dataset (UTDS):

In our web applications we normally use UTDS. UTDS is not easy to use but easy to administer. UTDS is so called because we get runtime errors in case there is any type (datatype) mismatch. UTDS is fast in terms of performance. It is used in small as well as in large enterprise level applications. In order to create UTDS we have to create each row and column of datatable in a dataset manually with specifying the datatype of each column as well.


XSD.exe is a tool in .NET framework SDK that generates the TDS using xml (schema) file generated when we drag a table into TDS using MS VS designer. An example of TDS in our code is:

DataSet dsPersons = new Persons().GetPersons();

gvPersons.DataSource = dsPersons;


Hope this will help you.

Riley K replied to aman on 09-Aug-11 04:35 AM
A typed dataset gives us easier access to the contents of the table through strongly typed programming that uses information from the underlying data schema. A typed DataSet has a reference to an XML schema file:

Dim s As String
s = dsCustomersOrders1.Customers(0).Customer

In contrast, if we are working with an untyped DataSet, the equivalent code looks like this:

Dim s As String
s = _ CType(dsCustomersOrders1.Tables("Custome
rs").Rows(0).Item("CustomerID"), String)

As the syntax is much simpler and more practical, using typed Datasets is much more handy.