16 April 2011

Difference between typed dataset and untyped dataset in .Net framework

Difference between typed dataset and untyped dataset in .Net framework

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.

An untyped dataset, in contrast, has no corresponding built-in schema. As in a typed dataset,
an untyped dataset contains tables, columns, and so on — but those are exposed only as collections.


Typed DataSet

// C#
// This accesses the CustomerID column in the first row of
// the Customers table.
string s;
s = dsCustomersOrders1.Customers[0].CustomerID;
Untyped Datasets

// C#
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];

In addition to being easier to work with, the syntax for the typed dataset provides type checking at compile time, greatly reducing the possibility of errors in assigning values to dataset members.

No comments:

Post a Comment

Comments Welcome

Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...