 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.

Slides:



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

Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004.
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.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
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.
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.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
Accessing SQL Server and OLE DB from.NET Svetlin Nakov Telerik Corporation
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
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.
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.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
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 7: Accessing Data by Using 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:
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.
ADO.NET connections1 Connecting to SQL Server and Oracle.
 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 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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlConnection Object ADO.NET - Lesson 02  Training time: 10 minutes 
The Problems HTTP is disconnected So many database vendors Create a simple consistent versatile interface on the data Look at ADO.NET classes OleDb SQL.
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
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
1 Database Programming with ADO.NET Kashef Mughal.
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
© 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:
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
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Reading Data with the SqlDataReader ADO.NET - Lesson 04  Training time: 10.
ASP.NET Programming with C# and SQL Server First Edition
Data Access with ADO.NET
Introduction to ADO.NET
DB Apps Introduction Intro to ADO.NET SQL SoftUni Team DB Apps Intro
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
Programming the Web Using ASP.Net
How to Create Login Form using vb.net and SqlServer Database
Lecture 6 VB.Net SQL Server.
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
ADO.Net and Stored Procedures
An Introduction to Entity Framework
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Database Programming By Abdul Hadi M. Alaidi.
Database Objects 1/12/2019 See scm-intranet.
Chapter 10 ADO.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Active Data Objects Binding ASP.NET Controls to Data
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Presentation transcript:

 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 also be a text file, an Excel spreadsheet, or an XML file  As you are probably aware, there are many different types of databases available  For example, there is Microsoft SQL Server, Microsoft Access, Oracle, Borland Interbase, and IBM DB2 etc….

 ADO.NET allows us to interact with different types of data sources and different types of databases  However, there isn't a single set of classes that allow you to accomplish this universally  Since different data sources expose different protocols, we need a way to communicate with the right data source using the right protocol

 Some older data sources use the ODBC protocol  Many newer data sources use the OleDb protocol  And there are more data sources every day that allow you to communicate with them directly through.NET ADO.NET class libraries  ADO.NET provides a relatively common way to interact with data sources, but comes in different sets of libraries  These libraries are called Data Providers and are usually named for the protocol or data source type they allow you to interact with.

Provider NameAPI prefix ODBC Data ProviderOdbc OleDb Data Provider i.e. Access or Excel OleDb Oracle Data ProviderOracle SQL Data ProviderSql

 The SqlConnection Object  The SqlCommand Object  The SqlDataReader Object  The DataSet Object  The SqlDataAdapter Object

ADO.NET Application ODBC Driver ODBCRDBMS ODBC OLE DB RDBMS.NET Data Provider Connection Command Data Reader Data Adapter OLE DB OLE DB Provider SQL Server

 To interact with a database, you must have a connection to it  The connection helps identify the database server, the database name, user name, password, and other parameters that are required for connecting to the data base  A connection object is used by command objects so they will know which database to execute the command on

 A SqlConnection is an object, just like any other C# object SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=DbName;Integrated Security=SSPI");

Connection String Parameter NameDescription Data SourceIdentifies the server. Could be local machine, machine domain name, or IP Address. Initial CatalogDatabase name. Integrated SecuritySet to SSPI to make connection with user's Windows login User IDName of user configured in SQL Server. PasswordPassword matching SQL Server User ID. SqlConnection conn = new SqlConnection( "Data Source=DatabaseServer;Initial Catalog=DbTestID=YourUserID;Password=YourPassword"); Security Support Provider Interface (SSPI) is an API used by Microsoft Windows systems to perform a variety of security related operations such as authentication.

 The purpose of creating a SqlConnection object is so you can enable other ADO.NET code to work with a database  Other ADO.NET objects, such as a SqlCommand and a SqlDataAdapter take a connection object as a parameter  The sequence of operations occurring in the lifetime of a SqlConnection are as follows  Instantiate the SqlConnection.  Open the connection.  Pass the connection to other ADO.NET objects.  Perform database operations with the other ADO.NET objects.  Close the connection.

 A SqlCommand object allows you to specify what type of interaction you want to perform with a database  For example, you can do select, insert, modify, and delete commands on rows of data in a database table

 Similar to other C# objects, you instantiate a SqlCommand object via the new instance declaration, as follows  SqlCommand cmd = new SqlCommand("select CategoryName from Categories", conn);

 // 1. Instantiate a new command with a query and connection SqlCommand cmd = new SqlCommand("select CategoryName from Categories", conn); // 2. Call Execute reader to get query results SqlDataReader rdr = cmd.ExecuteReader();

 // prepare command string string insertString insert into Categories (CategoryName, Description) values ('Miscellaneous', 'Whatever doesn''t fit elsewhere')"; // 1. Instantiate a new command with a query and connection SqlCommand cmd = new SqlCommand(insertString, conn); // 2. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery();

 // prepare command string string updateString update Categories set CategoryName = 'Other' where CategoryName = 'Miscellaneous'"; // 1. Instantiate a new command with command text only SqlCommand cmd = new SqlCommand(updateString); // 2. Set the Connection property cmd.Connection = conn; // 3. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery();

 // prepare command string string deleteString delete from Categories where CategoryName = 'Other'"; // 1. Instantiate a new command SqlCommand cmd = new SqlCommand(); // 2. Set the CommandText property cmd.CommandText = deleteString; // 3. Set the Connection property cmd.Connection = conn; // 4. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery();

 Sometimes all you need from a database is a single value, which could be a count, sum, average, or other aggregated value from a data set  // 1. Instantiate a new command SqlCommand cmd = new SqlCommand("select count(*) from Categories", conn); // 2. Call ExecuteNonQuery to send command int count = (int)cmd.ExecuteScalar();

 A SqlDataReader is a type that is good for reading data in the most efficient manner possible  You can *not* use it for writing data  You can read from SqlDataReader objects in a forward-only sequential manner  Once you've read some data, you must save it because you will not be able to go back and read it again  The forward only design of the SqlDataReader is what enables it to be fast  It doesn't have overhead associated with traversing the data or writing it back to the data source  Therefore, if your only requirement for a group of data is for reading one time and you want the fastest method possible, the SqlDataReader is the best choice

 SqlDataReader rdr = cmd.ExecuteReader();  The ExecuteReader method of the SqlCommand object, cmd, returns a SqlDataReader instance

 SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI");  SqlCommand cmd = new SqlCommand( "select * from Customers", conn);  conn.Open();  rdr = cmd.ExecuteReader();  while (rdr.Read()) { // get the results of each column string contact = (string)rdr["ContactName"]; }

 DataSets only hold data and do not interact with a data source.  It is the SqlDataAdapter that manages connections with the data source and gives us disconnected behavior  The SqlDataAdapter opens a connection only when required and closes it as soon as it has performed its task

 Open connection  Retrieve data into DataSet  Close connection  And performs the following actions when updating data source with DataSet changes:  Open connection  Write changes from DataSet to data source  Close connection

 In between the Fill and Update operations, data source connections are closed and you are free to read and write data with the DataSet as you need  Because the applications holds on to connections only when necessary, the application becomes more scalable

 DataSet dsCustomers = new DataSet();

 SqlDataAdapter daCustomers = new SqlDataAdapter( "select CustomerID, CompanyName from Customers", conn);  The SqlDataAdapter contains all of the commands necessary to interact with the data source.

 daCustomers.Fill(dsCustomers, "Customers");  The Fill method, in the code above, takes two parameters: a DataSet and a table name  The DataSet must be instantiated before trying to fill it with data

SQL Insert Update Delete Select DataSet Data Adepter XML Side

 DataAdepter = number of table  Data Connection = one for one Back End

Send Connection Request(Constring) Connection open Send Command (SqlCommand- Query) Receive result in sqldatareader Process when SQL query returns Single Row from database Front EndDatabase

Send Connection Request(Constring) Connection open Send Command (SqldataAdepter- Query) Receive result in Dataset Process when SQL query returns multiple Row from database Front EndDatabase