200 likes | 330 Vues
This guide provides a high-level overview of ADO.NET, a crucial framework for accessing databases programmatically. It explores its architecture, including the three-tier and two-tier models, and introduces key concepts such as data providers, SQL, and relational databases. You'll learn about vital ADO.NET objects like SqlConnection, SqlCommand, and SqlDataReader, as well as how to interact with data using SQL statements (INSERT, SELECT, DELETE, UPDATE). The document also highlights the use of various data sources and protocols within ADO.NET.
E N D
Introduction to ADO.NET High Level Overview
Topics • What is ADO.NET? • Three-tier model • Data Providers • SQL • Relational Database
What is ADO.NET? • Microsoft ActiveX Data Object (old) • ADO.NET object provides an API for accessing database systems programmatically • Interface/Interaction • Relational database • XML • Excel Spreadsheet • Text file • Object-orientated set of libraries • Used in • Windows • Console • Web (asp)
Three Tier Architecture Client Or User Interface Windows, Console, Web C# Front-end C# Middle-layer Business Layer Classes, Components ADO.NET Database Management System Data Store
Two Tier Architecture Client And Business Rules Windows, Console, Web C# Front-end Classes, Components ADO.NET Database Management System Data Store
Data Providers • Data sources (e.g. databases) • Expose different protocols • Choose the right protocol for the right database • Older data sources use ODBC • Newer data sources use OleDb • ODBC and OleDb are APIs
Namespaces Available • System.Data • Root namespace • System.Data.OleDB • Works with any data source • System.Data.SqlClient • Designed to work with Microsoft SQL Server
Some ADO.NET Objects • SqlConnection Object • SqlCommand Object • SqlDataReader Object • DataSet Object • SqlDataAdapter Object
SQL • Structured Query Language • ADO.NET interacts with relational database with the help of SQL • Need to know SQL in order to interact with a Database Management System (DBMS)
Relational Database • Uses tables • Each row is a record • Each record has a key field • A key field should be unique • Tables are “connected” via foreign keys (a key from another table)
Simple ERD • Entity Relationship Diagram • Entity more-or-less equates to a table • Each primary key can become a foreign key in another table
Relational Databases • Use SQL to write data into tables • INSERT statement • Use SQL to retrieve data from tables • SELECT statement • Use SQL to delete data from tables • DELETE statement • Use SQL to edit data in tables • UPDATE statement • See page 905 in Deitel & Deitel
Asking Specific Questions SELECT <fields> FROM <tables> WHERE <conditions> INNER JOIN <tables> GROUP BY <fields> ORDER BY <fields> • Structure of a query • Fields and tables are separated by commas (,) • Conditions use the usual operators (=, >, <, and, or)
SQL Examples • MS Access Chocolate Factory • MS Access • Own version of SQL (called Jet) • Queries similar to Oracle • Only good for SMALL applications • Not very robust • Not extensible (doesn’t support a large number of users) • Doesn’t delete data • Doesn’t handle concurrency issues very well • Gets big very quickly (bloats)
Sources • C# Station • http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx • Deitel & Deitel (Chapter 19) • Deitel & Deitel - C# 2005- (Chapter 20) • Gittleman (Chapter 15) • http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cossdk/html/a03327c1-e427-4c07-b3d4-808ce81c2c96.asp • http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_xml1_64md.asp