ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.

Slides:



Advertisements
Similar presentations
ADO vs ADO.NET ADOADO.NET Client/server coupledDisconnected collection of data from data server Uses RECORDSET object (contains one table) Uses DATASET.
Advertisements

By Chris Pascucci and FLF
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.
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 ADO.NET Chapter 1 ADO.NET 4.0 Development.
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
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.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
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.
Overview of ADO.NET with the.NET Framework Scalable Development, Inc. Building systems today that perform tomorrow.
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.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
PART 1 CREATING THE PRODUCT CATALOG. ROADMAP FOR THIS CHAPTER To implement the departments list, you’ll start with the database and make your way to the.
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.
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
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
ADO.NET. ADO.NET is a new, improved, and greatly expanded version of ADO that was developed for the Microsoft.NET initiative It incorporates all of the.
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.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
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.
Mauricio Featherman, Ph.D. Washington St. University
Accessing Data with Microsoft Visual C# Applications.
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
Databases – Unit 3 & 4.  SQL is not restricted to a specific database, however in class we will be looking at the two major database programmes in use.
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.
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.
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 and Stored Procedures
ADO.NET Framework.
Lecture 6 VB.Net SQL Server.
ADO.Net and Stored Procedures
Chapter 10 ADO.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Presentation transcript:

ADO.NET – part II August 2004 [ Marmagna Desai]

CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database SqlCommand SqlDataReader Inserting Data SqlCommand Datasets Selecting Data Updating Data Conclusion

ADO vs ADO.net Ultimate goal of ADO and ADO.net is same: Providing data access API. Though there are many differences. ADO relies on COM ADO.net relies on “managed-providers” defined by CLR

ADO vs ADO.net ……[cont] Main Differences: ADOADO.NET Connection ModelConnection Oriented Model is used mostly. Disconnected Model is used: Messeage-like Model. Disconnected AccessProvided by RecordSetProvided by DataAdapter and Dataset Data RepresentationOne Recordset for one Table One Dataset for many interrelated tables with relationships Data ExchangeBinary Mode – Firewall Problem Use XML and XSD schema types are fully supported XML SupportLimitedRobust Support

ADO vs ADO.net ……[cont] Connection Model: ADO: Client application needs to be connected always to data-server while working on the data. These results in open connections for long time and thus data can not be accessed in parallel. ADO.NET Client disconnects connection immediately the data is processed. This will cache data at client side to achieve better performance. Hence ADO.net creates “disconnected version of RecordSet object

ADO vs ADO.net ……[cont] Data Representation: Recordsets are generated one per table. This does not support hierarchical structure of data access. It will be programmer’s responsibility to define relationships among different recordsets. Rercordsets can not support data accessing from multiple sources. Above limitations are resolved by implementation of Dataset objects in ADO.net mode

ADO vs ADO.net ……[cont] Data Passing: ADO objects communicate in binary mode hence it will be really difficult to pass data across firewalls. ADO.net use XML for passing data

ADO.net Managed Providers ADO.net provides following three classes DBConnection DBCommand DBDataReader These classes are never used directly. The inherited set of classes called “managed providers” are used for different functionalities of data access

ADO.net Managed Providers These are the different providers Provider optimized for SQL 7 OLE – DB provider A generic ODBC provider Provider for Oracle These providers gathers information on various data sources and how to interact with them E.g. SQL data provider uses private protocol (tabular data stream) to provide information and access methods on SQL server.

Connecting to Database Following methods are very similar to ADO. They are connection oriented and hence leave open connection while retrieving the data from source. SQL managed provider contains the class called SqlConnection. This class is used to connect to the sql database. Code: [ Please see next slide]

Code….. Dim connStr as String = “server=localhost;uid=uid;pwd=pwd;database=northwind;" Dim conn as New SqlConnection (connStr) Conn.Open() “Access Data Records Conn.Close() This is very similar to ADO program. Only the SqlConnection will be replaced with ADODB.Connection.

Selecting Data SqlCommand class is defined in ADO.net to provide different functionalities like insert,update,delete etc. on selected database. It is similar to ADODB.Command class in ADO. SqlCommand retrieves and place data on objects called SqlDataReader SqlCommand does this using ExecuteReader() method. [Please see next slide for Code]

Code Dim conn As SqlConnection = Nothing Try conn = New SqlConnection(connStr) Dim cmd As New SqlCommand("Select StateCode, " & "StateName From States", conn) conn.Open() Dim reader As SqlDataReader = _ cmd.ExecuteReader(CommandBehavior.CloseConnection) Me.ddRegion.DataSource = reader Me.ddRegion.DataBind() Me.ddRegion.Items.Insert(0, New ListItem("Select One:", "")) Catch exp As Exception lblOutput.Text = "Error occurred: " + exp.Message Finally If (conn.State <> ConnectionState.Closed) Then conn.Close() End Try

Explanation A connection is made using SqlConnection SqlCommand is used to construct a query ExecuteReader is used to generate SqlDataReader object Bind data to DropDownList Server name ddRegion

Inserting Data SqlCommand can be used to perform insert,delete,update etc. operations on data. ExecuteNonQuery method is used for this purpose. This method does not allow results to return to the database. [Please see code in next slide]

Code Dim conn As New SqlConnection(connStr) Dim cmd As New SqlCommand("CustInsert", conn) cmd.CommandType = CommandType.StoredProcedure Me.txtCustomerID.Text) Me.txtName.Text) Me.txtCompany.Text) Me.txtTitle.Text) Me.txtAddress.Text) Me.txtCity.Text) Me.ddRegion.SelectedValue) Me.txtZip.Text)

Code ….[cont] Try conn.Open() cmd.ExecuteNonQuery() lblOutput.Text = "Your information was successfully saved!" Catch exp As Exception lblOutput.Text = "An error occurred:" + exp.Message Finally 'Ensure connection is closed If (conn.State <> ConnectionState.Closed) Then conn.Close() End Try

Datasets Datasets are new to ADO.net. It access data in Disconnected in maner It stores data in-memory and process it.

Datasets….[cont] Following are main features Datasets does not interact with data source directly. Data adapter is used to fill this gap. : SqlDataAdapter class SqlDataAdapter class provides functionalies such as insert, delete and update. SqlDataAdapter also provides method called Fill() which is used to fill up the Dataset. Once dataset is filled with data, it can define relationships among gathered data from different source. Dataset uses XML to transmit data among different components. Different views of data stored in dataset can be created using dataview calss.

Code Following code shows how to query database using SqlDataAdapter and fill the Dataset. Dim conn As SqlConnection = Nothing Try conn = New SqlConnection(connStr) ‘Create DataAdapter Dim da As New SqlDataAdapter("Select StateCode, " & _ "StateName From States", conn) ‘Create DataSet Dim ds As New DataSet ‘Fill DataSet da.Fill(ds, "States")

Code …cont ‘Access a DataTable in the DataSet and create a bindable view Dim view As DataView = ds.Tables(0).DefaultView Me.ddRegion.DataSource = view Me.ddRegion.DataBind() Me.ddRegion.Items.Insert(0, New ListItem("Select One:", "")) Catch exp As Exception lblOutput.Text = "Error occurred: " + exp.Message Finally If (conn.State <> ConnectionState.Closed) Then conn.Close() End Try

Conclusion Basically ADO.net adds following extended capabilities to ADO. Disconnected modeling Relational Database query and in-memory storage Hierarchical structure of data XML based transmission of data among components These additional features makes ADO.net considerable advancement in Microsoft Technology

Q? THANKS!!