Professional Documents
Culture Documents
NET
Objectives
Ver. 1.0
Session 5
Slide 1 of 23
In a disconnected environment, data is stored in datasets and manipulations are performed in the datasets. After the data has been manipulated in the dataset, the changes are updated to the database. A dataset is a disconnected, cached set of records that are retrieved from a database. The dataset acts like a virtual database containing tables, rows, and columns. The two main types of datasets are:
Typed dataset Untyped dataset
Ver. 1.0
Session 5
Slide 2 of 23
Typed Dataset:
A typed dataset is derived from the DataSet class and has an associated XML schema, which is created at the time of creation of the dataset. The XML schema contains information about the dataset structure such as the tables, columns, and rows. The XML Schema Definition (XSD) language is used to define the elements and attributes of XML documents. The structure of a typed dataset is decided at the time of its creation. When a typed dataset is created, the data commands are generated automatically by using the column names from the data source.
Ver. 1.0
Session 5
Slide 3 of 23
Untyped Dataset:
An untyped dataset does not have any associated XML schema. In an untyped dataset, the tables and columns are represented as collections. Because an XML schema is not created for an untyped dataset, the structure of an untyped dataset is not known during compilation. Untyped datasets find their use in cases where the structure of the schema is not decided during compilation or the data being used does not have a definite structure.
Ver. 1.0
Session 5
Slide 4 of 23
A dataset has its own object model, as shown in the following figure.
Ver. 1.0
Session 5
Slide 5 of 23
Ver. 1.0
Session 5
Slide 6 of 23
The following list describes some parameters that can be specified for a column:
The name of the column The data type of the column Whether the column is read only Whether the column permits null values Whether the value of the column must be different in each row Whether the column is an auto-increment column Whether the column is an expression column
Ver. 1.0
Session 5
Slide 7 of 23
Consider the following code snippet used for adding columns in a DataTable:
DataSet ds = new DataSet(); DataTable dt = ds.Tables.Add(); dt.Columns.Add(Store Id, typeof(string)); dt.Columns.Add(Store Name, typeof(string)); dt.Columns.Add(Address, typeof(string));
Creating a DataSet object Creating a DataTable object Adding columns in a DataTable
Ver. 1.0
Session 5
Slide 8 of 23
Ver. 1.0
Session 5
Slide 9 of 23
Answer:
1. Find()
Ver. 1.0
Session 5
Slide 10 of 23
In ADO.NET, you can navigate through multiple tables to validate and summarize the data by using the DataRelation object. By using primary key and foreign key constraints that use a DataRelation object, you can create the relationship between multiple tables. The primary key is a unique index and ensures the uniqueness of data stored in that table for that particular row. The foreign key is a constraint on a table that can reference one or more columns in that table. The table that has a primary key constraint is known as the Parent table, and the table that has a foreign key constraint is known as the Child table.
Ver. 1.0
Session 5
Slide 11 of 23
SetDefault
SetNull
Ver. 1.0
Session 5
Slide 12 of 23
Ver. 1.0
Session 5
Slide 13 of 23
Error
Ignore
Ver. 1.0
Session 5
Slide 14 of 23
A dataview provides a dynamic view of data stored in a datatable. If any data is modified in the datatable, the dataview associated with the datatable will also show the modified data. Let us understand the object model of a dataview.
Ver. 1.0
Session 5
Slide 15 of 23
Ver. 1.0
Session 5
Slide 16 of 23
Ver. 1.0
Session 5
Slide 17 of 23
A dataview provides a sorted or filtered view of data in a datatable. Sorting in a DataTable by using a DataView object is done by using the Sort property. Filtering a DataTable by using the DataView object is done by using the RowFilter and RowStateFilter properties.
Ver. 1.0
Session 5
Slide 18 of 23
Answer:
2. RowFilter
Ver. 1.0
Session 5
Slide 19 of 23
Problem Statement:
Jane, a member of the HR team at Tebisco, needs to store the details of employees who have recently joined the organization. You need to create an application for Jane that will enable her to add and save the details of new employees, and if required, delete records of employees who are no longer working in the organization. The employee code should get automatically generated based on the format in the table. The employee details will be stored in the empdetails table of the HR database.
Ver. 1.0
Session 5
Slide 20 of 23
A typed dataset is derived from the DataSet class and has an associated XML schema, which is created at the time of creation of a dataset. An untyped dataset does not have any associated XML schema. As a result, the structure of an untyped dataset is not known during compilation.
Ver. 1.0
Session 5
Slide 21 of 23
Ver. 1.0
Session 5
Slide 22 of 23
Ver. 1.0
Session 5
Slide 23 of 23