.NET Data Access and Manipulation

Slides:



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

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.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
.NET Mobile Application Development Data in Distributed Systems Accessing Data with.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 ?
In C# program Before you can start using the ODBC class definitions, you will need to include the right module. using System.Data.Odbc; // ODBC definitions.
C# programming with database Basic guideline. First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
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.
Accessing SQL Server and OLE DB from.NET Svetlin Nakov Telerik Corporation
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.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
IT533 Lectures DataBinding Controls. Installations Microsoft® SQL Server® 2008 Express Download the sample MDF files from the course’s web site CodeWeek3.zip.
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.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.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.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
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.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
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.
Module 7: Accessing Data by Using 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
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
C# Programming in Depth Prof. Dr. Bertrand Meyer March 2007 – May 2007 Chair of Software Engineering Lecture 10: Database Lisa (Ling) Liu.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
Why ADO.NET Not your father’s Data Access.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
HNDIT Rapid Application Development
Module 4 Introduction ADO.NET.
C# .NET Software Development
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
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.
Querying Information in a Database. CONTENTS Relational Database Systems Creating Database with SQL Server Reading Data with LINQ Requirements to Get.
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.
 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.
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
Data Access with ADO.NET
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET and Stored Procedures
ADO.NET Framework.
.NET Data Access and Manipulation
Lecture 6 VB.Net SQL Server.
ADO.Net and Stored Procedures
מתחברים למסד נתונים היכרות עם ADO.Net.
برنامه نویسی سیستم های شی گرا
Chapter 10 ADO.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Presentation transcript:

.NET Data Access and Manipulation ADO.NET .NET Data Access and Manipulation

Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects Steps of Data Access

What is ADO.NET? A data-access technology that enables applications to connect to data stores and manipulate data contained in them in various ways A set of object oriented libraries to interact data sources Database, text file, excel file… Former version was ADO (ActiveX Data Object)

What is ADO.NET? An object oriented framework that allows you to interact with database systems

Objective of ADO.NET Support disconnected data architecture, Tight integration with XML, Common data representation Ability to combine data from multiple and varied data sources Optimized facilities for interacting with a database

ADO.NET Architecture

ADO.NET Core Objects Core namespace: System.Data .NET Framework data providers: Libraries that makes you interact with data sources Data Provider Namespace SQL Server (sql server) System.Data.SqlClient OLE DB (access, excel) System.Data.OleDb ODBC (older systems) System.Data.Odbc Oracle System.Data.OracleClient

ADO.NET Core Objects Object Description Connection Establishes a connection to a specific data source. (Base class: DbConnection) identify server and user Command Executes a command against a data source. Exposes Parameters and can execute within the scope of a Transaction from a Connection. (The base class: DbCommand) DataReader Reads a forward-only, read-only stream of data from a data source in a sequential manner. It is fast since read only. (Base class: DbDataReader) DataAdapter Populates a DataSet and resolves updates with the data source. (Base class: DbDataAdapter) DataTable Has a collection of DataRows and DataColumns representing table data, used in disconnected model DataSet Represents a cache of data. Consists of a set of DataTables and relations among them (support disconnected opr.)

Connected Data Access Model

Disconnected Data Access Model

Pros and Cons - + Connected Disconnected Database Resources Network Traffic Memory Usage Data Access

Steps of Data Access: Disconnected Environment Defining the connection string Defining the connection Defining the command Defining the data adapter Creating a new DataSet object SELECT -> fill the dataset object with the result of the query through the data adapter Reading the records from the DataTables in the datasets using the DataRow and DataColumn objects UPDATE, INSERT or DELETE -> update the database through the data adapter

EXAMPLE using System; using System.Data; using System.Data.SqlClient; namespace SampleClass { class Program static void Main(string[] args) string connStr = Properties.Settings.Default.connStr; SqlConnection conn = new SqlConnection(connStr); string queryString = "SELECT * from Employees;"; SqlDataAdapter da = new SqlDataAdapter(queryString,conn); conn.Open(); DataSet ds = new DataSet(); da.fill(ds); // Work on the data in memory using // the DataSet (ds) object } EXAMPLE

Disconnected – Update, Delete, Insert SqlDataAdapter da = new SqlDataAdapter(); DataSet ds = new DataSet(); SqlCommandBuilder builder = new SqlCommandBuilder(da); da.Fill(ds); INITIAL CODE DataRow dr = ds.Tables[0].Rows[0]; dr.Delete(); da.UpdateCommand = builder.GetUpdateCommand(); da.Update(ds); DELETE DataRow dr = ds.Tables[0].Rows[0]; dr["CustomerName"] = "John"; da.UpdateCommand = builder.GetUpdateCommand(); da.Update(ds); UPDATE DataRow dr = ds.Tables[0].NewRow(); dr["CustomerName"] = "John"; dr["CustomerSurName"] = "Smith"; ds.Tables[0].Rows.Add(dr); da.UpdateCommand = builder.GetUpdateCommand(); da.Update(ds); INSERT

Steps of Data Acces : Connected Environment Create connection Create command (select-insert-update-delete) Open connection If SELECT -> use a DataReader to fetch data If UPDATE,DELETE, INSERT -> use command object’s methods (e.g. ExecuteNonQuery) Close connection

EXAMPLE static void Main() { string connectionString = Properties.Settings.Default.connStr; string queryString = "SELECT CategoryID, CategoryName FROM dbo.Categories;"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString,connection); try connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) Console.WriteLine("\t{0}\t{1}“,reader[0],reader[1]); } reader.Close(); connection.close(); catch (Exception ex) Console.WriteLine(ex.Message); EXAMPLE

Connected – Update, Delete, Insert Command class core methods: ExecuteNonQuery : Executes a SQL statement against a connection object ExecuteReader: Executes the CommandText against the Connection and returns a DbDataReader ExecuteScalar: Executes the query and returns the first column of the first row in the result set returned by the query

Connected – Update, Delete, Insert string connString = Properties.Settings.Default.connStr; SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand("delete from Customers" + "where custID=12344", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); Can be an update or insert command

Choosing a DataReader or a Dataset The type of functionality application requires should be considered Use a dataset to: Cache data locally in your application so that you can manipulate it Remote data between tiers or from an XML Web service Interact with data dynamically such as binding to a Windows Forms control or combining and relating data from multiple sources Perform extensive processing on data without requiring an open connection to the data source, which frees the connection to be used by other clients If readonly data is needed use DataReader to boost performance