Introduction to Database Processing with ADO.NET

Slides:



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

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.
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
VB.NET Database Access ISYS 812. 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.
Objective In this session we will discuss about : What is ADO. NET ?
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
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.
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.
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.
 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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with Disconnected Data The DataSet and SqlDataAdapter ADO.NET - Lesson.
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.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
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:
ADO.NET Part 2. Slide 2 Overview Slide 3 Introduction to the DataGridView Control It’s a two-dimensional grid containing rows and columns Its use in.
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.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
HNDIT Rapid Application Development
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
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
Working with Data Lesson 4. Objectives DataSource Controls A requirement for most modern Web sites is that they be dynamic. –Static pages are not often.
 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
Data Access with ADO.NET
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Programming the Web Using ASP.Net
Lecture 6 VB.Net SQL Server.
Active Data Objects Binding ASP.NET Controls to Data
ADO.NET Accessing Databases in VS.NET
VB.NET Using Database.
Tonga Institute of Higher Education
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
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
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Introduction to Database Processing with ADO.NET

The ASP.NET / ADO.NET Conundrum The tools and wizards are wonderful for simple applications As applications become more complex and “real” You need to write code between the controls and the data providers Nested controls and one-to-many views become complex At some point, the visual designers become useless

Lecture Overview Introduce ASP.NET data sources Introduce the ASP.NET data bound controls Show a few SIMPLE examples to get us started

History of ADO Open Database Connectivity (ODBC) was created to provide a uniform API to access SQL database servers OLE DB evolved from ODBC and provided a COM based interface Next came the first versions of ADO, which encapsulated OLE DB ADO.NET is the current generation of ADO and uses .NET Managed Providers

History of ADO: While not a problem, Microsoft has stepped away from all MSAccess support The data controls are gone Necessary Jet versions are not usually installed You can make them work though So we will use SQL Server Express in this course I’ll show how to connect to SQL Server

.NET and SQL Server Use the Server Explorer to manage connections

Table Designer Use it to create tables and manage schema elements Three views GUI editor Script Summary

Table Designer

ADO.NET -The Role of Managed Providers Managed providers interact with a data source and return data to an application Data sources are typically (almost always) disconnected After data is returned to the application, connections are closed

ADO / ASP.NET NOTE The capabilities of ASP and ADO are vast There are many ways to accomplish the same task DataReaders vs. DataAdapters DataSource controls vs. manual binding

ADO.NET Namespaces / Classes (Intro) There are many of these Some you don’t need to work with directly Mastery of the topic requires that you understand what the controls do and how they interact with the underlying classes

ADO.NET Namespaces (1) Here’s the fabric System.Data System.Data.SqlClient System.Data.OleDb System.Data.SqlTypes

ADO.NET Classes (1) Connection – creates the connection with the data source (database) Support is provided for ORACLE, SQL Server, Access, etc. Transaction – allows for transactional processing Command – typically an SQL statement executed against a database server Could be a stored procedure Parameter – a parameter passed to a command

ADO.NET Classes (2) DataAdapter – a database object that returns a disconnected set of records (DataSet and DataTable) DataReader – a forward-only reader to get database records

Introduction to Connections Executing a database command is generally a two-step process Create a connection Prepare and execute a command The ASP.NET controls help automate much of the process There are specific connection classes for OLE DB, SQL Server and others They all work the same way

Connection Strings There are tools to build these for you based on the database provider Connection strings are typically stored in the web.config file They store all information needed to establish a database connection More later

Connection Strings (Example) Connection strings are usually stored in web.config The following reads the connection string from web.config

Connection Strings (Example) The SqlConnection object represents the connection itself. Its properties depict the connection status

Executing Commands (Introduction) Use the SqlCommand object to Return one record one field (ExecuteNonQuery) Execute SQL INSERT, UPDATE, DELETE statements Return records in the form of a DataTable Return records one row at a time (DataReader)

SqlCommand Object (Using 1 row) The OleDbCommand or SqlCommand objects work the same way Set the CommandText property to the SQL statement to execute Set the CommandType property to CommandType.Text Set the Connection property to an existing Connection object

SqlCommand Object (Using 1 row) To return one field from one row, call ExecutScalar() on the SqlCommand object

SqlCommand Object (Returning Nothing) Use the ExecuteNonQuery method to execute SQL statements that do not return values INSERT / UPDATE / DELETE As before, the CommandText property stores the SQL statement Two ways to do INSERT / UPDATE /DELETE With parameters Roll the statement by hand

SqlCommand Object (Returning Nothing - Manual) Use create the CommandText, CommandType and Connection as before The INSERT / UPDATE / DELETE statements get contorted

SqlCommand Object (Parameters 1 ) Parameters provide the preferred way to pass data to INSERT / UPDATE / DELETE and other SQL statements Parameters begin with an @ in the SQL statement

SqlCommand Object (Parameters 1 ) Then we create the parameters as part of the command object We are adding items to the parameters collection

Using the DataReader This is straight out of the book There are much better ways to read data but here is the first cut It’s a forward only reader Call Read to read the first and subsequent records Create an SqlCommand object as before Call ExecuteReader to initialize Call Read to read each record Index contains the field name

Using the DataReader (example)

Reading Multiple Records Here, we use the DataSet and DataTable objects along with the DataAdapter Steps Create SqlCommand with the SELECT statement as before Create a new SqlDataAdapter Create a DataSet Call Fill on the DataAdapter to populate the DataSet

Reading Multiple Records

Introduction to Data Sources Data sources establish the connection between an ASP.NET application and a database These are not the same controls as the desktop controls

Data Source Controls (Categories) Tabular SqlDataSource – For SQL databases ObjectDataSource – For custom business objects Hierarchical SiteMapDataSource – For menus XmlDataSource – To bind XML documents

Data Sources (Core Concepts) The ASP.NET data source controls are bound to a page rather than the application They belong to System.Web rather than System.Data so they are again unique to ASP.NET Underneath the hood, there is a DataSet You can use the System.Data classes from an ASP.NET application Visual Studio does a great job configuring the data source controls

Data Sources (Under the Hood 1) The Wizards configure properties to Write SELECT statements and customize them Write INSERT, UPDATE, and DELETE statements that are executed by other bound controls

Data Sources (Under the Hood 2) The Properties window tells the tale