Week 6: Create, Add, Delete, and Edit Data in A Disconnected Environment
Week 6: Create, Add, Delete, and Edit Data in A Disconnected Environment
Objectives in chapter
Create a DataSet graphically. Create a DataSet programmatically. Add a DataTable to a DataSet. Add a relationship between tables within a DataSet. Navigate a relationship between tables. Merge DataSet contents. Copy DataSet contents. Create a typed DataSet. Create DataTables. Manage data within a DataTable. Create and use DataViews. Use the OleDbDataAdapter object to access an ADO Recordset or Record. Generate DataAdapter commands automatically by using the Command-Builder object.
Chapter content
Lesson 1:Creating DataSet Objects Lesson 2: Creating DataTable Objects. Lesson 3: Creating DataAdapter Objects Lesson 4: Working with Data in DataTable Objects Lesson 6: Creating and Using DataView Objects
Why DataSet?
Perform database modifications
always disconnected
To transfer data between tiers have .NET framework (Linux, Unix, Windows) To send between computers across network by HTTP protocol in XML format To manipulate the data without an open connection To relate data from multiple sources To bind data to a Windows form Power data structure
Event an application without database, we can using dataset instead of arraylist, array
Populating DataSets
Manual From existing database (using DataAdapter) Read from XML,XSD data files
DataSet Components
DataTable DataColumn DataRow Constraint DataRelation DataView
DataTable
Represents one table in DataSet Are accessed using the DataSet's Tables property
Collection of DataTables Using index : ds.tables(0) Using name: ds.tables(authors) A Columns property A Rows property
DataSet DataTable
DataRow DataColumn
DataTable
DataRow
DataColumn
Access to data-cell
Table.Rows(index).Item(index)
Example
Dim Cid as DataColumn = authors.Columns.Add("ID",gettype(integer)) Cid.AutoIncrement = true
DataRow Class
A DataRow object provides access to one row of data in a DataTable DataSet
A DataTable's DataRow objects contain all the data in the DataTable Table.NewRow method Column name Column number DataColumn object DataTable
DataRow DataColumn
Create
DataTable
DataRow
DataColumn
Core Pro./methods
Populating DataSet-Manual
1.
1. 2. 3. 4.
2.
1. 2.
Exercise 1: Creating a typed DataSet with the DataSet Designer Questions after finishing?
10
11
DataColumn Class
Describes one column of data in a DataTable
DataColumn objects describe table's schema DataAdapters can generate the required DataColumns Doesnt have Value property ColumnName DataType DataSet DataTable
DataRow DataColumn
DataTable
DataRow
DataColumn
Ex. Gettype(integer)
12
13
Unique Constraint
Dim Unique As New UniqueConstraint(NorthwindDataSet.Orders.OrderIDColumn) NorthwindDataSet.Orders.Constraints.Add(Unique)
14