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.

Slides:



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

ADO.Net Modelo para acesso a dados nas aplicação.Net Componentes: DataSet.Net Data providers: Connection Command DataReader DataAdapter.
ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA.
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.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
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.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
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.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS546.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Chapter 9 Using the SqlDataSource Control. References aspx.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ASP.Net Web Applications. Characteristics of a typical data driven web application Web Server HTML Graphics Active-X Java Applets HTTP Request ADO / JDBC.
Chapter 71 Building Data-Driven ASP.NET Applications Introduction to ASP.NET By Kathleen Kalata.
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 Data Access MacDonald Ch. 15 MIS 324 Professor Sandvig.
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)
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.
Chapter 3 Introduction to ADO.NET 3.1 The ADO and ADO.NET ActiveX Data Object (ADO) is developed based on Object Linking and Embedding (OLE) and Component.
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.
Module 7: Accessing Data by Using ADO.NET
ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information.
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.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
Why ADO.NET Not your father’s Data Access.
Mauricio Featherman, Ph.D. Washington St. University
ADO.NET AND STORED PROCEDURES - Swetha Kulkarni. RDBMS ADO.NET Provider  SqlClient  OracleClient  OleDb  ODBC  SqlServerCE System.Data.SqlClient.
Why ADO.NET Not your father’s Data Access.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
HNDIT Rapid Application Development
2314 – Programming Language Concepts Introduction to ADO.NET.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
ADO.NET in VB.NET 2005 ITE 370 4/26/2017.
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.
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.
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
C# 1 CSC 298 ADO.NET. C# 2 ADO.NET  A data access technology that maps very well to the world of the web (disconnected architecture)  data is retrieved.
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Lecture 6 VB.Net SQL Server.
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
Tonga Institute of Higher Education
Chapter 10 ADO.
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:

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 Creating a Connection to a Database Displaying a DataSet in a List-Bound Control Accessing Data with DataSets Accessing Data with DataReaders Using Multiple Tables

ADO.NET provides a set of classes for working with data. ADO.NET provides: An evolutionary, more flexible successor to ADO A system designed for disconnected environments A programming model with advanced XML support A set of classes, interfaces, structures, and enumerations that manage data access from within the.NET Framework What is ADO.NET?

Using Namespaces Using the Imports statement to import namespaces Namespaces used with ADO.NET include: System.Data System.Data.SqlClient System.Data.OleDb Imports System.Data Imports System.Data.SqlClient Imports System.Data Imports System.Data.SqlClient

DataSet SQL Server.NET Data Provider OLE DB.NET Data Provider SQL Server 7.0 (and later) OLEDB sources (SQL Server 6.5) OleDbConnection OleDbDataAdapter SqlDataAdapter SqlConnection DataTable The ADO.NET Object Model

Using the ADO.NET Object Model

SQL Server 2000 DataSet DataTable Physical storage OleDb Database SqlDataAdapter SqlConnection DataTable Web server memory OleDbDataAdapter OleDbConnection What is a Dataset?

Accessing Data with ADO.NET Database 4.Return the DataSet to the Client 5.Client manipulates the data 2.Create the SqlConnection and SqlDataAdapter objects 3.Fill the DataSet from the DataAdapter and close the connection SqlDataAdapter SqlConnection List-Bound Control 1.Client makes request Update the DataSet 7.Use the SqlDataAdapter to open the SqlConnection, update the database, and close the connection Client Web server DataSet

The DataAdapter Object Model sp_SELECT Command SelectCommandUpdateCommandInsertCommandDeleteCommand DataAdapter Command Connection sp_UPDATEsp_INSERTsp_DELETE Database DataSet DataReader

Generating a DataSet You can generate a DataSet… …through the UI… Creates a DataSet that allows you to access data as an object …or through code… and then fill… Dim ds As New DataSet() DataAdapter1.Fill(ds) DataAdapter2.Fill(ds) DataAdapter1.Fill(ds) DataAdapter2.Fill(ds)

What are List-Bound Controls? Controls that connect to a data source and display the data List-bound controls include the following: DropDownList ListBox CheckBoxList RadioButtonList DataGrid DataList Repeater

Displaying DataSet Data in List-Bound Controls Set the properties Fill the DataSet, then call the DataBind method DataAdapter1.Fill(ds) lstEmployees.DataBind() DataAdapter1.Fill(ds) lstEmployees.DataBind()PropertyPropertyDescriptionDescription DataSource  The DataSet containing the data DataMember  The DataTable in the DataSet DataTextField  The field in the DataTable that is displayed DataValueField  The field in the DataTable that becomes the value of the selected item in the list

Using DataSets vs. DataReaders Supported by Visual Studio.NET tools Slower access Forward-only Bind to one control only Based on one SQL statement from one database Read-only Manually coded Faster access Forward and backward scanning of data Bind to multiple controls Includes multiple tables from different databases Read/write access to data DataReaderDataSet DisconnectedConnected

What is a DataReader? Forward-only, read-only Fast access to data Connected to a data source Manage the connection yourself Manage the data yourself, or bind it to a list-bound control Uses fewer server resources

Creating a DataReader To use a DataReader: 1.Create and open the database connection 2.Create a Command object 3.Create a DataReader from the Command object 4.Call the ExecuteReader method 5.Use the DataReader object 6.Close the DataReader object 7.Close the Connection object Use Try…Catch…Finally error handling

Reading Data from a DataReader Call Read for each record Returns false when there are no more records Access fields Parameter is the ordinal position or name of the field Get functions give best performance Close the DataReader Close the connection Do While myReader.Read() str &= myReader(1) str &= myReader("field") str &= myReader.GetDateTime(2) Loop Do While myReader.Read() str &= myReader(1) str &= myReader("field") str &= myReader.GetDateTime(2) Loop

Binding a DataReader to a List-Bound Control Create the Control Bind to a DataReader dgAuthors.DataSource = dr dgAuthors.DataBind() dgAuthors.DataSource = dr dgAuthors.DataBind()

SQL Server Security Client Send the username and password in clear text. Do not send the username and password. Just send that the user has been authenticated. Mixed mode authentication Windows only authentication SQL Server Only ASPNET account is granted access Web Server Windows authentication or… SQL Server Each user account added to SQL Server logins group Web Server Default ASP.NET settings Here is the username and password

Creating the Connection Using SqlConnection Setting connection string parameters Connection timeout Data source Initial catalog Integrated security Dim strConn As String = "data source=localhost; " & _ "initial catalog=northwind; integrated security=true" Dim conn As New SqlConnection(strConn) Dim strConn As String = "data source=localhost; " & _ "initial catalog=northwind; integrated security=true" Dim conn As New SqlConnection(strConn) Password Persist security info Provider User ID

Store the query in a DataAdapter The DataAdapter constructor sets the SelectCommand property Set the InsertCommand, UpdateCommand, and DeleteCommand properties if needed Creating a DataAdapter Dim da As New SqlDataAdapter _ ("select * from Authors", conn) Dim da As New SqlDataAdapter _ ("select * from Authors", conn) da.SelectCommand.CommandText da.SelectCommand.Connection da.SelectCommand.CommandText da.SelectCommand.Connection

Creating a DataSet Create and populate a DataSet with DataTables Fill method executes the SelectCommand Access a DataTable Dim ds As New DataSet() da.Fill(ds, "Authors") Dim ds As New DataSet() da.Fill(ds, "Authors") Dim r As DataRow Dim str As String For Each r in _ ds.Tables("Authors").Rows str &= r(2) str &= r("au_lname") Next Dim r As DataRow Dim str As String For Each r in _ ds.Tables("Authors").Rows str &= r(2) str &= r("au_lname") Next ds.Tables("Authors").Rows.Count

Using a DataView A DataView can be customized to present a subset of data from a DataTable The DefaultView property returns the default DataView of the table Setting up a different view of a DataSet Dim dv As DataView = ds.Tables("Authors").DefaultView Dim dv As New DataView (ds.Tables("Authors")) dv.RowFilter = "state = 'CA'" Dim dv As New DataView (ds.Tables("Authors")) dv.RowFilter = "state = 'CA'"

Binding a DataSet to a List-Bound Control Create the control Bind to a DataSet or a DataView dg.DataSource = ds dg.DataMember = "Authors" dg.DataBind() dg.DataSource = ds dg.DataMember = "Authors" dg.DataBind()

Storing Multiple Tables Add the first table Add the subsequent table(s) daCustomers = New SqlDataAdapter _ ("select * from Customers", conn1) daCustomers.Fill(ds, "Customers") daCustomers = New SqlDataAdapter _ ("select * from Customers", conn1) daCustomers.Fill(ds, "Customers") Orders Customers daOrders = New SqlDataAdapter _ ("select * from Orders", conn2) daOrders.Fill(ds, "Orders") daOrders = New SqlDataAdapter _ ("select * from Orders", conn2) daOrders.Fill(ds, "Orders") conn2conn1 DataSet

Creating Relationships Identify parent column Identify child column Create DataRelation Dim dr As New DataRelation _ ("name", parentCol, _ childCol) ds.DataRelations.Add(dr) Dim dr As New DataRelation _ ("name", parentCol, _ childCol) ds.DataRelations.Add(dr) Dim parentCol As DataColumn = _ ds.Tables("Customers").Columns("CustomerID") Dim parentCol As DataColumn = _ ds.Tables("Customers").Columns("CustomerID") Dim childCol As DataColumn = _ ds.Tables("Orders").Columns("CustomerID") Dim childCol As DataColumn = _ ds.Tables("Orders").Columns("CustomerID") Orders table Customers table DataSet parentCol childCol DataRelation

Programmatically Navigating Between Tables Using Relationships ds.Tables(index).Rows(index).GetChildRows("relation") ds.Tables(index).Rows(index).GetParentRow("relation") ds.Tables(index).Rows(index).GetChildRows("relation") ds.Tables(index).Rows(index).GetParentRow("relation") Customers Orders GetChildRows GetParentRow DataSet

Visually Navigating Between Tables Using Relationships Dim tableView As DataView Dim currentRowView As DataRowView tableView = New DataView(ds.Tables("Customers")) currentRowView = tableView(dgCustomers.SelectedIndex) dgChild.DataSource = currentRowView.CreateChildView("CustOrders") Dim tableView As DataView Dim currentRowView As DataRowView tableView = New DataView(ds.Tables("Customers")) currentRowView = tableView(dgCustomers.SelectedIndex) dgChild.DataSource = currentRowView.CreateChildView("CustOrders") Customers Orders CreateChildView DataRowView DataView DataSet