Christopher M. Pascucci.NET Programming: Databases & ADO.NET.

Slides:



Advertisements
Similar presentations
By Chris Pascucci and FLF
Advertisements

Lecture 14 A new Introduction to Databases: DB Review & ADO.NET Models – Connected and Disconnected 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.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
CSC 2720 Building Web Applications Database and SQL.
Objective In this session we will discuss about : What is ADO. NET ?
Introduction to Databases: DB Review & ADO.NET Models – Connected and Disconnected.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
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.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
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.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
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.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
CSC 2720 Building Web Applications Database and SQL.
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.
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.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
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)
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Data Types Lesson 4. Skills Matrix Table A table stores your data. Tables are relational in that they are organized as rows and columns (a matrix). Each.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
HNDIT Rapid Application Development
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Module 4 Introduction ADO.NET.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
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.
1 A Very Brief Introduction to Relational Databases.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
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.
SQL Basics Review Reviewing what we’ve learned so far…….
.NET Data Access and Manipulation
Introduction to Database Programming with Python Gary Stewart
Based on Murach (ch 17) and Deitel Slides 1. o Knowledge o Describe the hardware components of a typical multi-user system. o Describe the software components.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
SQL and SQL*Plus Interaction
Lecture 6 VB.Net SQL Server.
By Chris Pascucci and FLF
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.
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Christopher M. Pascucci.NET Programming: Databases & ADO.NET

Database Basics  A relational database is a tool for storing and manipulating information efficiently and effectively in the sense that data is protected from accidental loss or corruption, that it doesn't use more resources (human or computer) than necessary.  A relational database uses tables to store and manipulate data.  Each table contains one or more records, or rows, that contain information about a single entry.  Records contain a set of related fields that are used to store data.  Each record contains one or more fields, or columns, that contain a single piece of data.  Most tables include a primary key field that uniquely identifies each record (row) in a table.  Storing students (records) by name in a large university will make it difficult to find students with the same name. Giving each student a StudentID uniquely identifies each student.  SSN uniquely identify each American in the U.S.

Database Basics  The tables in a relational database are related to each other through their key columns. A column that identifies a related row in another table is called a foreign key. Table

SQL Concepts  Structured Query language (SQL) is an English – like language that is used to manipulate data in the database.  There are 4 basic SQL statements that are needed to work with data in a database.  SELECT – used to query a table and find specific information based on some criteria.  UPDATE – used for modifying data in one or more rows (records) in a table.  INSERT – used to add one or more rows (records) to a table.  DELETE – used to delete one or more rows (records) in a table.  Each Database Management System (DBMS) may have a slightly different version of SQL called a dialect that was derived from the standard language.

SQL SELECT Syntax  The result of a Select statement is called a result set, which is a logical set of rows that consists of all of the columns and rows requested by the Select statement.  Example: Select column_name [, column_name2]... From table_name [Where selection-criteria] [Order By column_name [Asc|Desc] [, column_name2[Asc|Desc]]...] Select ProductID, Name, UnitPrice From Products Where CategoryID = 'Props' Order By UnitPrice Result Set shown above. Click button to view full table. Note: Use (*) to select all columns. Select * From Products

SQL INSERT Syntax  The Insert statement is used to add a new row (record) to a table. It can be used to set fields to specified values as it adds the new record.  Example: Insert [Into] table_name [(column_name-list)] Values (values-list) Insert [Into] Products (ProductID, Description, UnitPrice, OnHand) Values (“abc01”,”Toy”,”$19.99”,”50”) Click button to view full table. Note: Order of column-list items and value-list items is very important…!

SQL UPDATE Syntax  The Update statement is used to modify/edit existing data.  Example: Update table_name Set expression [, expression2]... [Where selection-criteria] Update Products Set UnitPrice = “25.79” Where ProductID = “arm01” Click button to view full table.

SQL DELETE Syntax  The Delete statement is used to remove a row or rows from a table.  Example: Delete [From] table_name [Where selection-criteria] Delete From Products Where ProductID = “arm01” Click button to view full table.

SQL Example Table  The full table used in SQL examples. Return to last viewed slide

ADO.NET Introduction  ADO.NET is the primary data access API for the.NET Framework.  It provides the classes that are used to create applications that use a database.  These classes become objects you can use in your application to manage and use database connections.  To use these classes in the.NET Framework you must import the namespace System.Data that contains all these useful classes.  Data that is used in your application is stored in a Dataset, which contains one or more Data Tables.  Data in the Dataset is independent of the database that was used to retrieve it.  The connection to the database is typically closed after data is retrieved from the database. The connection is opened again when it’s needed.  A Data Adapter is used to load data into the Data Table.  Data Adapter’s major function is to manage the exchange of data between the Dataset and database.

ADO.NET Explained  Dataset:  Data in the Dataset is independent of the database that was used to retrieve it.  The connection to the database is typically closed after data is retrieved from the database. The connection is opened again when it’s needed.  Since the application actually works with a copy of data from the database it is called a Disconnected Data Architecture because of its “disconnected” nature.  Data Adapter:  Manages the exchange of data between the Dataset and a database.  Issues an SQL statement (Select, Insert, Update or Delete) that is stored in the command object.  The command object uses a connection object to connect to the database and retrieve or update the data.  The data is transferred back to the Data Adapter, which then stores it in a Dataset that can be used by the application.

ADO.NET Explained

 An ADO.NET data provider connects to a data source such as SQL Server, Oracle, or an OLE DB data source, and provides a way to execute commands against that data source.  The ADO.NET classes responsible for working directly with a database are provided by the.NET Data Providers:  The.NET Framework includes data providers for SQL Server, Oracle, OLE DB, ODBC, etc…  The Data Providers included in the.NET Framework contain the same objects, although their names and some of their properties and methods are different. For example, the SQL Server version of a database connection is the SqlConnection, while the OLE DB version is an OleDbConnection.

ADO.NET Programming The following is an example of code needed to establish a connection and retrieve data from a database. Dim strSQL As String Dim strConnection As String Dim objDataSet As New DataSet() Dim objAdapter As OleDbDataAdapter Dim objConnection As OleDbConnection strConnection = "provider=SQLOLEDB.1;server=dwarf.cis.temple.edu;Database=fa08_c nn;User id=fa08_c430901nn;Password=yourpassword“ strSQL = "SELECT * from Product" objConnection = New OleDbConnection(strConnection) objAdapter = New OleDbDataAdapter(strSQL, objConnection) objAdapter.Fill(objDataSet) Using OleDb Provider objects Dataset used to hold data retrieved from the DB. Connection object used to create a connection to the DB. DataAdapter used to manage a connection, exchange of data and issue SQL commands to the DB. Fills a Dataset with data retrieved from the DB.

Connected vs. Disconnected Data  ADO.NET contains two different approaches to work with data in a database: Connected Data Architecture and the Disconnected Data Architecture.  Connected Data Architecture:  Represents the objects that insist on having an open connection available for them to work and interact with the data source.  ADO.NET provides classes to communicate directly with a data source.  Disconnected Data Architecture:  Represents the objects that open and close a connection to the data source as needed.  Your application works with data that was copied from the data source. Any changes made to the “copied” data in the Dataset will be later reconciled with the data source.  Connected applications alone don't fulfill the demands of today’s distributed applications.  Improved performance, more efficient and more complex than the connected approach.

Disconnected Data Architecture  The major advantage of the disconnected approach is that it improves system performance due to the fact that it uses less resources for maintaining connections when working with a data source.  However, there is a disadvantage to this approach that occurs when two or more users try to update the same row of a table, which is called a concurrency problem.  This problem occurs because once data is retrieved from the database, the connection is dropped. As a result, the DBMS can’t manage the update process.  There are two ways that ADO.NET can handle concurrency problems: 1.Optimistic Concurrency – The program checks to see if there has been a change to the row since it was retrieved. If it has, the update or deletion will be refused and a concurrency exception will be thrown that your program must handle. 2.“Last In Wins” – Since no checking is done, the row that was updated by the last user will overwrite changes made to the row by the previous user.  Another way to avoid concurrency problems is to retrieve and update only one row at a time.

ADO.NET Terms Summary  Dataset:  Data in the Dataset is independent of the database that was used to retrieve it.  Data Adapter:  Manages the exchange of data between the Dataset and a database.  Allowing a DataSet and DataTable to be filled from the data source and later reconciled with the data source.  Connection:  Connects to the data source.  Command:  Executes commands (SQL statements) against the data source.  Data Providers:  The ADO.NET classes responsible for working directly with a database.  Data Reader  Retrieves query results in a read-only, forward-only connected result set.

SQL Server Data Types  Large value data types: varchar(max), nvarchar(max), and varbinary(max)  Large object data types: text, ntext, image, varchar(max), nvarchar(max), varbinary(max), and xml  For more information on SQL Server Data Types on the MSDN website.SQL Server Data Types  Character Strings:  Use char when the sizes of the column data entries are consistent.  Use varchar when the sizes of the column data entries vary considerably.  Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.  Use text when there is a variable-length of non-unicode data.  Unicode Character Strings:  Use nchar when the sizes of the column data entries are probably going to be similar.  Use nvarchar when the sizes of the column data entries are probably going to vary considerably.  Use ntext when there is a variable-length of unicode data.  Exact Numbers:  Use tinyint when the numbers range from 0 – 255 (1-byte of storage)  Use smallint when the numbers range from -32,768 to 32,767 (2-bytes of storage)  Use int when the numbers range from -2,147,483,648 to 2,147,483,647 (4-bytes of storage)  Use bigint when the numbers range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (8-bytes of storage)