Module 7: Accessing Data by Using ADO.NET

Slides:



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

Database Connections with ASP.Net
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Introduction to Database Processing with ADO.NET.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Programming in ADO.NET: Data-Centric Applications and ADO.NET Original copyright by Microsoft, 2002, with minor modifications by Dan Eaves, 2005.
Objective In this session we will discuss about : What is ADO. NET ?
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
CIS 764 – Presentation Somil Chandwani.  With Microsoft Data Access Components (MDAC), developers can connect to and use data from a wide variety of.
C# programming with database Basic guideline. First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ODBC, OLE DB, and ADO Introduction Dr. Ron Eaglin.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
A Simple Introduction. What is ADO.net? First the word ADO stands for ActiveX Data Objects And it is an integral part of.Net Framework of Microsoft hence.
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.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
 2006 Pearson Education, Inc. All rights reserved Database, SQL and ADO.NET.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with Disconnected Data The DataSet and SqlDataAdapter ADO.NET - Lesson.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
10/26/20151 Chapter 3 Introduction to ADO.NET In this chapter, you will: Learn the basic classes in ADO.NET and its architecture Learn the different ADO.NET.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Module 2: Connecting to Data Sources. Overview Choosing a.NET Data Provider Defining a Connection Managing a Connection Handling Connection Exceptions.
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.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
HNDIT Rapid Application Development
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
1 Database Programming with ADO.NET Kashef Mughal.
C# .NET Software Development
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.
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
Querying Information in a Database. CONTENTS Relational Database Systems Creating Database with SQL Server Reading Data with LINQ Requirements to Get.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlCommand Object ADO.NET - Lesson 03  Training time: 15 minutes  Author:
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
.NET Data Access and Manipulation
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
Integrating Data Lesson 6.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Programming the Web Using ASP.Net
Lecture 6 VB.Net SQL Server.
ADO.NET Accessing Databases in VS.NET
VB.NET Using Database.
Chapter 10 ADO.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Module 7: Accessing Data by Using ADO.NET

Module Overview Overview of Data Access Reading and Writing Relational Data Reading and Writing XML Data

Lesson 1: Overview of Data Access ADO.NET Object Model XML Data Access Data Access Namespaces Choosing a .NET Framework Data Provider What Are Connected and Disconnected Operations? Accessing Data by Using the Visual Studio 2005 IDE Binding Data to Controls Demonstration: Accessing Data by Using the Visual Studio 2005 IDE

Data provider-specific classes Data provider-independent classes ADO.NET Object Model ADO.NET Connected model vs. disconnected model Data provider interfaces Data provider-specific classes Data provider-independent classes SqlConnection SqlCommand SqlDataReader SqlDataAdapter DataSet DataTable

XML Data Access XmlReader 1 XmlWriter 2 XmlDocument DOM 3 XmlElement

Data Access Namespaces Description System.Data Core ADO.NET architecture System.Data.Common Shared classes System.Data.OracleClient Classes for Oracle System.Data.OleDb Classes for OLE-DB-compatible data sources System.Data.Odbc Classes for ODBC data sources System.Data.Sql Core SQL Server classes System.Data.SqlClient Classes for SQL Server version 7.0 and later data sources System.Xml Classes for XML data sources …

Choosing a .NET Framework Data Provider Database .NET Framework Data Provider for Microsoft SQL Server SQL Server 7.0 and later Microsoft Data Engine (MSDE) .NET Framework Data Provider for OLE DB SQL Server (SQLOLEDB) Oracle (MSDAORA) Microsoft Jet (Microsoft.Jet.OLEDB.4.0) .NET Framework Data Provider for ODBC SQL Server Microsoft ODBC for Oracle Microsoft Access Driver (*.mdb) .NET Framework Data Provider for Oracle Oracle client software version 8.1.7 and later

AdventureWorks Database AdventureWorks Database What Are Connected and Disconnected Operations? Connected model Disconnected model DataSet .NET application .NET application Open connection Open connection Run commands Create DataSet Retrieve results Close connection Close connection Manipulate data Open connection AdventureWorks Database AdventureWorks Database Update tables Close connection

Accessing Data by Using the Visual Studio 2005 IDE 1 On the Data menu, click Add New Data Source 2 Define a new database connection 3 Save the connection string in the app.config file 4 Specify the tables you want in the DataSet 5 Specify a name for the DataSet

Binding Data to Controls 1 Add a control to a Windows form 2 Choose the data source for the control 3 Add queries to the table adapter, if necessary 4 Write code to fill the table in the DataSet 5 Write code to save the table in the DataSet

Demonstration: Accessing Data by Using the Visual Studio 2005 IDE Create a new data source Add a DataGridView control and set properties Bind the DataGridView control to a data source Update the data source query Add code to save changes to the data on the FormClosed event Build and run the application

Lab: Accessing Data by Using a DataGridView Control Exercise 1: Binding Data to Controls in a Form (15 minutes)

Lesson 2: Reading and Writing Relational Data Connecting to a Data Source Creating and Running ADO.NET Commands How to Retrieve Data by Using a Data Reader What Is a Data Adapter? How to Fill and Access DataSet Data How to Save a DataSet to a Database Guidelines for Secure Coding with ADO.NET

Connecting to a Data Source Database 1. Import namespaces 2. Create a Connection object 3. Call the Open method to open the connection 4. Call the Close method to close the connection .NET Application

Creating and Running ADO.NET Commands Method Description ExecuteScalar Executes a query and returns a single result ExecuteReader Executes a query and retrieves rows from a data source ExecuteNonQuery Executes a query that performs an action in the database, and returns the number of rows affected

How to Retrieve Data by Using a Data Reader 1 Create a connection object 2 Create a command object and specify an SQL query 3 Open the database connection 4 Invoke the ExecuteReader method and obtain a data reader object 5 Use the data reader object to iterate through the result set 6 Close the database connection .NET Application Database

What Is a Data Adapter? DataSet Database DataAdapter Invoke Fill method to populate DataSet 1 Invoke Update method to merge changes 2 DataSet Database DataTable Object DataAdapter Fill Method Update Method

How to Fill and Access DataSet Data 1 Import required namespaces 2 Create a SqlDataAdapter object 3 Set the SelectCommand property to an SQL query 4 Create a DataSet object 5 Open the database connection 6 Invoke the Fill method 7 Close the database connection

How to Save a DataSet to a Database 1 Import required namespaces 2 Create a SqlDataAdapter object 3 Set the command property to an SQL query 4 Create a DataSet object 5 Open the database connection 6 Invoke the update method 7 Close the database connection

Guidelines for Secure Coding with ADO.NET Do not echo user security credentials when opening a connection Use Windows authentication if possible Store connection strings in the application configuration file Encrypt connection strings Validate user input Prevent SQL injection attacks Stored procedures . . .

Lab: Accessing Data by Using ADO.NET Commands Exercise 1: Creating and Running Simple Commands (30 minutes) Exercise 2: (OPTIONAL) Creating and Running Query Commands (30 minutes)

Lesson 3: Reading and Writing XML Data How to Read and Write a DataSet as XML Data How to Read XML Data by Using XmlReader How to Write XML Data by Using XmlWriter How to Process XML Data by Using the Document Object Model

How to Read and Write a DataSet as XML Data Save a DataSet as XML DiffGram IgnoreSchema WriteSchema Load XML into a DataSet Auto Fragment InferSchema InferTypeSchema ReadSchema DataSet

How to Read XML Data by Using XmlReader 1 Create an XmlReaderSettings object 2 Create an XmlReader object 3 Iterate through the nodes in the XML document 4 Retrieve the value of nodes 5 Close the document

How to Write XML Data by Using XmlWriter 1 Create an XmlWriterSettings object 2 Create an XmlWriter object 3 Write the start of the XML document 4 Write nodes to the XML document 5 Write the end of the XML document

How to Process XML Data by Using the Document Object Model DOM: A standard API for reading and writing XML data Node types include: root, element, child element, and attribute Operations: Read the content of XML data Move randomly around the XML document Add, modify, clone, and delete content in the XML document Create a new XML document

Lab: Reading and Writing XML Data Exercise 1: Reading and Writing a DataSet as XML Data (15 minutes)

Lab Discussion What are the four core data providers in the .NET Framework? What classes can you use to establish a connection to a SQL Server database? What are the advantages and disadvantages of connected and disconnected operations? What are the available options for reading and writing XML data?