Module 4: Building DataSets. Overview Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

1.NET Web Forms DataGrid © 2002 by Jerry Post. 2 Data Grid Has Many Uses  The grid uses HTML tables to display multiple rows of data. It is flexible.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
 Open the Paradise.exe file  Application displays records in the Books database  Allows the store manager to enter an author’s name (or part of a name)
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Disconnected Data Applications: using Datasets, XML and Transactions.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
ASP.NET Programming with C# and SQL Server First Edition
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
Overview of Data Access MacDonald Ch. 15 MIS 324 Professor Sandvig.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
® Microsoft Office 2013 Access Building a Database and Defining Table Relationships.
1 Chapter 7 Query-By-Example by Monica Chan CS157B Professor Lee.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Analyzing Data For Effective Decision Making Chapter 3.
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.
Key Applications Module Lesson 21 — Access Essentials
Oracle Data Integrator Transformations: Adding More Complexity
® Microsoft Office 2010 Building a Database and Defining Table Relationships.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Microsoft Office 2007 Access Chapter 3 Maintaining a Database.
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Part II. Query Types On the design query table pane, right click and the cascading window will appear.
Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of.
Maintaining a Database Access Project 3. 2 What is Database Maintenance ?  Maintaining a database means modifying the data to keep it up-to-date. This.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Making the Most of WinForms 2.0 Data Binding Rajiv Sodhi Microsoft India.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
DataSets Demystified. Who I am Shawn Wildermuth Senior Consultant with Magenic Technologies ( C# MVP INETA.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Module 5 Data Classes DataView – DataGridView Control 1.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
Windows Database Applications CIS 341 Chapter 5. Objectives Update database Navigate records Event handler Bound control maintenance Update data source.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Database, SQL and ADO.NET
ADO.NET Framework.
Module 5: Implementing Data Integrity by Using Constraints
VB.NET Using Database.
Database Applications
Chapter 10 Accessing Database Files
Presentation transcript:

Module 4: Building DataSets

Overview Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data Relationships Modifying Data in a DataTable Sorting and Filtering

Lesson: Working in a Disconnected Environment Typically disconnected scenarios.NET Framework classes used in scenarios

Disconnected Architecture EmployeesOrdersCustomersProductsCategories Products SqlDataAdapterOleDbDataAdapter SQL Server 2000 CustomersOrders SQL Server 6.5 DataSet XML Web service XmlDataDocument XML File

Lesson: Building DataSets and DataTables What Are DataSets, DataTables, and DataColumns? The DataSet Object Model How to Create a DataSet, a DataTable, and a DataColumn How to Create a Primary Key Constraint Using Unique Constraints Creating Custom Expressions

What Are DataSets, DataTables, and DataColumns? ServerData Store Database Connection Stored Procedure DataSet DataTable

The DataSet Object Model Common collections Tables (collection of DataTable objects) Relations (collection of DataRelation objects) Data binding to Web and Windows controls supported Schema can be defined programmatically or using XSD DataRow DataColumn DataTable DataRelation Constraints

How to Create a DataSet, a DataTable, and a DataColumn Creating a DataSet Drag and drop a DataSet control from the Toolbox Creating a DataTable Edit the Tables collection of a DataSet by using the Properties window Creating a DataColumn and adding it to a DataTable Edit the Columns collection of a DataTable by using the Properties window

How to Create a Primary Key Constraint Set the PrimaryKey property of the DataTable Select the columns in order Does not allow the naming of the constraint Edit the Constraints collection of the DataTable Add a UniqueConstraint Name the constraint Select the columns Check the primary key box

Using Unique Constraints Two types of constraints UniqueConstraint ForeignKeyConstraint Creating a constraint Edit the Constraints collection of a DataTable UniqueConstraint Array of DataColumns Can be the primary key for the DataTable

Creating Custom Expressions Definition Custom expressions are columns derived from calculations, rather than stored values Using the DataColumn Expression property Sum([Unit Price] * [Quantity]) Aggregate functions can use parent/child relationships Avg, Count, Sum, Max, Min

Lesson: Binding and Saving a DataSet How to Bind Data to a Windows Control How to Bind a DataSet to a DataGrid How to Save and Open a DataSet

How to Bind Data to a Windows Control Simple data binding Binding to a simple control that can only display a single value – for example, a text box Complex data binding Binding to a more complex control that can display multiple values – for example, a data grid All controls have a (DataBindings) collection Use the Properties window to edit data bindings Best practice: use an intermediate DataView

How to Bind a DataSet to a DataGrid DataSource property Can be a DataSet, DataTable, or DataView DataMember Can be a DataTable if the DataSource is a DataSet Or, use the (DataBindings) collection Best practice: Use an intermediate DataView

How to Save and Open a DataSet Two DataSet methods ReadXml WriteXml Pass the path and filename as a string parameter ReadXml raises an exception if the file does not exist WriteXml overwrites existing files

Lab 4.1: Building, Binding, Opening, and Saving DataSets Exercise 1: Building the Custom DataSet Exercise 2: Opening and Saving the DataSet Exercise 3: Coding the Menus in the Windows Application

Lesson: Defining Data Relationships Using Foreign Key Constraints to Restrict Actions How to Create a Foreign Key Constraint What Is a DataRelation Object? How to Create a DataRelation Object How to Navigate Related DataTables

Using Foreign Key Constraints to Restrict Actions A ForeignKeyConstraint enforces referential integrity If the EnforceConstraints property of a DataSet is True Restricting actions performed in related tables DeleteRule and UpdateRule properties ActionActionDescriptionDescription Cascade Deletes or updates related rows. This is the default. SetNull Sets values in related rows to DBNull. SetDefault Sets values in related rows to the DefaultValue. None No action is taken, but an exception is raised.

How to Create a Foreign Key Constraint Use Properties window DataSet must have at least two tables Parent table must have a primary key Add a ForeignKeyConstraint to the child table Choose the matching columns Choose Update and Delete rules Write code Visual Basic ExampleVisual C# Example

What Is a DataRelation Object? Definition A DataRelation object defines a navigational relationship, NOT a constraint relationship Used by presentation objects (for example, a DataGrid) to allow easier navigation (for example, “drill down” capability from parent rows to child rows) Used by expression columns to calculate aggregates A DataSet has a Relations collection

How to Create a DataRelation Object Use the Properties window Or, write code dsNorthwind.Relations.Add( _ "FK_CustomersOrders", _ dtCustomers.Columns("CustomerID"), _ dtOrders.Columns("CustomerID"), _ True) ' create a ForeignKeyConstraint too

How to Navigate Related DataTables The GetChildRows method of the DataRow Pass a DataRelation name as the parameter Example: Dim drCustomer As DataRow Dim drOrder As DataRow For Each drCustomer In _ dsNorthwind.Tables("Customer").Rows For Each drOrder In drCustomer.GetChildRows( _ "FK_CustomersOrders") ' process row Next

Lesson: Modifying Data in a DataTable How to Insert a New Row How to Position on a Row Modifying Data in a Table How to Delete a Row What Are the RowState and RowVersion Properties? How to Handle the DataTable Events

How to Insert a New Row Creating a new row Dim drNewEmployee As DataRow = _ dtEmployees.NewRow() Filling the new row drNewEmployee("EmployeeID") = 11 drNewEmployee("LastName") = "Smith" Appending the row to a DataTable dtEmployees.Rows.Add(drNewEmployee) Creating, filling, and appending a row simultaneously dtEmployees.Rows.Add( _ New Object() {11, "Smith"})

How to Position on a Row CurrencyManager object Position property points to current row Position = 0 is first row Each DataTable and DataView can have one CurrencyManager Visual Basic Example DataTable DataView CurrencyManager

Modifying Data in a Table The BeginEdit method of DataRow class Disables the raising of events and exceptions EndEdit and CancelEdit methods of DataRow class Enable the raising of events and exceptions How to modify data in a table Dim drEmployee As DataRow = dtEmployees.Rows(3) drEmployee.BeginEdit() drEmployee("FirstName") = "John" drEmployee("LastName") = "Smith" drEmployee.EndEdit()

How to Delete a Record The Remove method of the DataRowCollection class Completely removes the row from the collection Example: dtEmployees.Rows.Remove(drEmployee) The Delete method of the DataRow class Marks the row as deleted Hidden, but still accessible if necessary Example: drEmployee.Delete

What Are the RowState and RowVersion Properties? RowState property of a DataRow Added, Deleted, Detached, Modified, Unchanged DataViewRowState enumeration Used with a DataView to filter rows of a certain state CurrentRows, OriginalRows, and so on DataRowVersion enumeration is used when retrieving values using the Item property Current, Default, Original, Proposed HasVersion method of a DataRow AcceptChanges and RejectChanges methods

How to Handle the DataTable Events Example: Private WithEvents dtProducts As DataTable Private Sub dtProducts_RowDeleted( _ ByVal sender As Object, _ ByVal e As System.Data.DataRowChangeEventArgs) _ Handles dtProducts.RowDeleted ' write code here End Sub DataTable events list

Lesson: Sorting and Filtering How to use the Select method What Is a DataView Object? How to Define a DataView How to Use a DataView at Design Time

How to Use the Select Method DataTables have a Select method Gets an array of DataRow objects that match the filter in the order of the sort, and that match the specified state Three optional parameters Filter expression, for example, "City='London'" Sort, for example, "CompanyName ASC" DataViewRowState, for example, Deleted

What Is a DataView Object? ServerData Store Database Connection Stored procedure DataSet DataTable Windows and Web controls DataView

How to Define a DataView Creating a DataView by using form controls Creating a DataView programmatically Dim dvProducts As New _ DataView(dsNorthwind.Tables("Products")) dvProducts.Sort = "UnitPrice" dvProducts.RowFilter = "CategoryID > 4" grdProducts.DataSource = dvProducts Applying a DataView to a DataTable dvProducts.Table = _ dsNorthwind.Tables("Products")

How to Use a DataView at Design Time DataViews allow sorting and filtering at design time A DataView cannot span multiple DataTables, unlike the View object in SQL Server Use presentation-level objects instead (for example, the DataGrid control, report designers, and so on) Every DataTable has a DefaultView property

Review Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data Relationships Modifying Data in a DataTable Sorting and Filtering

Lab 4.2: Manipulating DataSets and Modifying Data Exercise 1: Creating Relationships Exercise 2: Navigating Relationships Exercise 3: Editing Rows in a DataTable Exercise 4: Sorting and Filtering with DataViews