Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.

Slides:



Advertisements
Similar presentations
Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004.
Advertisements

By Chris Pascucci and FLF
 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
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.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
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.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Objective In this session we will discuss about : What is ADO. NET ?
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
ASP.NET Programming with C# and SQL Server First Edition
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
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.
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)
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
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.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
© 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.
ASP.NET Rina Zviel-Girshin Lecture 5
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
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.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
© 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
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
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.
© 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.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
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.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Introduction Because database applications today reside in a complicated environment, various standards have been developed for accessing database servers.
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
Database, SQL and ADO.NET
Introduction to Database Processing with ADO.NET
 2012 Pearson Education, Inc. All rights reserved.
JDBC.
Databases Intro (from Deitel)
Chapter 8 Working with Databases and MySQL
Chapter 22 - SQL, MySQL, DBI and ADO
Chapter 10 ADO.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010

Bina Nusantara University 3 Outline Materi Introduction Relational Database Model Structured Query Language ADO.NET Object Model

Bina Nusantara University 4 Introduction A database is an integrated collection of data. A database management system (DBMS) provides mechanisms for storing and organizing data in a manner that is consistent with the database’s format. Database management systems enable programmers to access and store data without worrying about the internal representation of databases. Today’s most popular database systems are relational databases.

Bina Nusantara University 5 Introduction Almost universally, relational databases use a language called Structured Query Language (SQL) to perform queries and to manipulate data. A programming language connects to, and interacts with, a relational database via an interface-software that facilitates communication between a database management system and a program. C# programmers communicate with databases and manipulate their data through Microsoft ActiveX Data Objects TM (ADO), ADO.NET.

Bina Nusantara University 6 Relational Database Model The relational database model is a logical representation of data that allows relationships among data to be considered without concern for the physical structure of data. numbernamedepartmentsalaryLocation 23603Jones New Jersey 24568Kerwin New Jersey 34589Larson Los Angeles 35761Myers Orlando 78321Neuman n New Jersey Record/Row Primary keyField/Column

Bina Nusantara University 7 Structured Query Language (SQL) Basic SELECT Query SELECT * FROM tableName (*) indicates that all columns from the tableName table of the database should be selected. Example: SELECT * FROM Authors

Bina Nusantara University 8 SQL Query Keywords SQL KeywordDescription SELECTSelects (retrieves) fields from one or more tables FROMSpecifies tables from which to get fields or delete records. Required in every SELECT and DELETE statement. WHERESpecifies criteria that determine the rows to be retrieved. INNER JOINJoins records from multiple tables to produce a single set of records. GROUP BYSpecifies criteria for grouping records. ORDER BYSpecifies criteria for ordering records. INSERTInserts data into a specified table. UPDATEUpdates data in a specified table. DELETEDeletes data from a specified table.

Bina Nusantara University 9 WHERE Clause In most cases, users search a database for records that satisfy certain selection criteria. Only records that match the selection criteria are selected. SELECT fieldName1, fieldName2, … FROM tableName WHERE criteria Example: To select the name, salary, and location fields from table Employee in which the salary is greater than 1800.

Bina Nusantara University 10 WHERE Clause SELECT name, salary, location FROM Employee WHERE salary > 1800 numbernamedepartmentsalaryLocation 23603Jones New Jersey 24568Kerwin New Jersey 34589Larson Los Angeles 35761Myers Orlando 78321Neuman n New Jersey

11 ORDER BY Clause The result of a query can be arranged in ascending or descending order using the optional ORDER BY clause. SELECT fieldName1, fieldName2,…FROM tableName ORDER BY field ASC SELECT fieldName1, fieldName2,…FROM tableName ORDER BY field DESC ASC specifies ascending order (lowest to highest) DESC specifies descending order (highest to lowest) Field specifies the field whose values determine the sorting order Bina Nusantara University

12 ORDER BY Clause Example: SELECT name, salary, location FROM Employee ORDER BY name ASC

Bina Nusantara University 13 Merging Data from Multiple Tables: INNER JOIN Database designers often split related data into separate tables to ensure that a database does not store data redundantly. Often, it is necessary for analysis purposes to merge data from multiple tables into a single set of data. Referred to as joining the tables, this is accomplished via an INNER JOIN operation in the SELECT query. An INNER JOIN merges records from two or more tables by testing for matching values in a field that is common to the tables.

Bina Nusantara University 14 Merging Data from Multiple Tables: INNER JOIN SELECT fieldName1, fieldName2, … FROM table1 INNER JOIN table2 ON table1.fieldName = table2.fieldName The ON part of the INNER JOIN clauses specifies the fields from each table that are compared to determine which records are joined.

Bina Nusantara University 15 INSERT Statement The INSERT statement inserts a new record in a table. INSERT INTO tableName ( fieldName1, fieldName2, …, fieldNameN ) VALUES ( value1, value2, …, valueN )

Bina Nusantara University 16 ADO.NET Object Model 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. The ADO.NET object model provides an API for accessing database systems programmatically. ADO.NET was created for the.NET Framework and is the next generation of ActiveX Data Objects TM (ADO). Namespace System.Data is the root namespace for the ADO.NET API.

Bina Nusantara University 17 ADO.NET Object Model ADO.NET allows us to interact with different types of data sources and different types of databases. Different data sources expose different protocols, we need a way to communicate with the right data source using the right protocol.

ADO.NET Object Model ADO.NET Data Providers are class libraries that allow a common way to interact with specific data sources or protocols. The library APIs have prefixes that indicate which provider they support. Provider Name API prefix Data Source Description ODBC Data ProviderOdbc Data Sources with an ODBC interface. Normally older data bases. OleDb Data ProviderOleDb Data Sources that expose an OleDb interface, i.e. Access or Excel. Oracle Data ProviderOracleFor Oracle Databases. SQL Data ProviderSqlFor interacting with Microsoft SQL Server. Borland Data ProviderBdp Generic access to many databases such as Interbase, SQL Server, IBM DB2, and Oracle.

Bina Nusantara University 19 ADO.NET Object Model ADO.NET includes many objects you can use to work with data. The SqlConnection Object 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.

20 ADO.NET Object Model The SqlCommand Object The process of interacting with a database means that you must specify the actions you want to occur. This is done with a command object. You use a command object to send SQL statements to the database. The SqlDataReader Object Many data operations require that you only get a stream of data for reading. The data reader object allows you to obtain the results of a SELECT statement from a command object. For performance reasons, the data returned from a data reader is a fast forward-only stream of data. This means that you can only pull the data from the stream in a sequential manner. This is good for speed, but if you need to manipulate data, then a DataSet is a better object to work with.

Bina Nusantara University 21 ADO.NET Object Model The DataSet Object DataSet objects are in-memory representations of data. They contain multiple Datatable objects, which contain columns and rows, just like normal database tables. The SqlDataAdapter Object Sometimes the data you work with is primarily read-only and you rarely need to make changes to the underlying data source. Some situations also call for caching data in memory to minimize the number of database calls for data that does not change. The data adapter makes it easy for you to accomplish these things by helping to manage data in a disconnected mode. The data adapter fills a DataSet object when reading the data and writes in a single batch when persisting changes back to the database.

Bina Nusantara University 22 The SqlConnection Object A SqlConnection is an object, just like any other C# object. SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI"); Common parts of a connection string Connection String Parameter Name Description Data Source Identifies 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.

Bina Nusantara University 23 The SqlConnection Object The following shows a connection string, using the User ID and Password parameters: SqlConnection conn = new SqlConnection( "Data Source=DatabaseServer;Initial Catalog=Northwind;User ID=YourUserID;Pass=YourPass");

Bina Nusantara University 24 Using a SqlConnection 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: 1.Instantiate the SqlConnection. 2.Open the connection. 3.Pass the connection to other ADO.NET objects. 4.Perform database operations with the other ADO.NET objects. 5.Close the connection.

Bina Nusantara University 25

Bina Nusantara University 26 References station.com/Tutorials/ADODotNet/Lesson01.aspxhttp:// station.com/Tutorials/ADODotNet/Lesson01.aspx