Mục tiêu Ưu điểm của ADO.NET Kiến trúc của ADO.NET

Slides:



Advertisements
Các bản thuyết trình tương tự
TRANG COVER Viết tiêu đề Ebook vào chỗ này…
Advertisements

Công nghệ phần mềm Các quy trình phần mềm.
Teen Challenge Staff Training Course
CHÚA NHẬT 4 MÙA THƯỜNG NIÊN
CHÚA NHẬT 33 MÙA THƯỜNG NIÊN NĂM B
CHÚA NHẬT 20 MÙA THƯỜNG NIÊN NĂM A TWENTIETH SUNDAY IN ORDINARY TIME
GIẢI PHÁP CHAT BOT HỖ TRỢ NGƯỜI NỘP THUẾ
LỄ ĐỨC MARIA LÀ MẸ THIÊN CHÚA
Các nguyên tắc làm việc với ASP
Lễ Chúa Giêsu Lên Trời Năm C
Tiêu đề Mẫu Powerpoint Thêm tiêu đề L.O.G.O.
PHÒNG TÀI NGUYÊN VÀ MÔI TRƯỜNG CÁC CÔNG TÁC BẢO VỆ MÔI TRƯỜNG
Hệ điều hành Windows Sever 2003
ThS. Phạm Đức Thành Lập trình trên Windows ThS. Phạm Đức Thành
CHÚA NHẬT 29 MÙA THƯỜNG NIÊN
“Khi Chúa Giêsu đã chịu phép rửa và đang cầu nguyện, thì trời mở ra”.
ASP Giáo viên: TS. Trương Diệu Linh Bộ môn Truyền thông & Mạng
Thẻ tham khảo nhanh (QRC)
BIDV Czech Rep. Representative Office
Chương 5 KẾT NỐI ĐẾN DATA SOURCE.
CHALLENGES & OPPORTUNITIES
Hùng Phương & Thanh Quảng thực hiện
Chương 3 Exception.
VÒNG 1 - BẢNG B Đại học Công nghiệp Hà Nội Học viện Kỹ thuật Quân sự 2
Xinh đẹp! Beautiful!.
LỄ CHÚA THÁNH THẦN HIỆN XUỐNG
TWENTY-FIFTH SUNDAY IN ORDINARY TIME
Chúa Nhật 13 Thường Niên Năm C Hùng Phương & Thanh Quảng thực hiện
Dạy những học viên đọc kém Teaching Students with Low Reading Levels
Chương 3 – Các kỹ thuật gỡ lỗi và kiểm thử chương trình
Chương 7 INTERFACE.
THE HOLY FAMILY OF JESUS, MARY AND JOSEPH
Hướng dẫn sử dụng Tôn Nữ Phương Mai Tháng 3/2013.
Hướng dẫn sử dụng hệ thống họp trực tuyến của Bộ GD&ĐT
Lương Trần Hy Hiến - LINQ to SQL Lương Trần Hy Hiến -
Đứng Vững & Giữ Chặt Stand Firm & Hold Fast
Bài 3: Ngôn ngữ lập trình C#
Chương 02 CẤU TRÚC VÀ CÁC THÀNH PHẦN CHƯƠNG TRÌNH C/C++
Chương 5 ỨNG DỤNG CSDL VÀ ADO.NET.
CHƯƠNG II: CHUẨN ETHERNET
BS ĐOÀN XUÂN DUNG Phòng CT-MRI
Bài 1: giới thiệu C# và .NET framework
Chương 5 DataSets.
Hiểu Biết về Kết Quả SBAC CAASPP – California Assessment of Student Performance and Progress (Đánh Giá của California về Thành Quả và Tiến.
CHÚA NHẬT 5 MÙA THƯỜNG NIÊN
17th Sunday in Ordinary Time - Year C Chúa Nhật 17 Thường Niên Năm C
THE NATIVITY OF THE LORD CHRISTMAS
Tác giả: Đa-vít Bát-ti By Dave Batty
Maria thì ghi nhớ tất cả những việc đó và suy niệm trong lòng
PALM SUNDAY OF THE LORD’S PASSION
Tin Mừng Chúa Giêsu Kitô theo Thánh Matthêu.
Chuyên đề : Web Design Bộ môn KTMT – Viện CNTT&TT
Cài đặt và thiết lập DNS cho Domain
LỄ ĐỨC MARIA, MẸ THIÊN CHÚA MARY, THE HOLY MOTHER OF GOD
HƯỚNG DẪN BẦU CHỌN VỊNH HẠ LONG
Spondyloarthritis BS Mã Nguyễn Minh Tùng.
SẮP XẾP, TÌM KIẾM, LỌC DỮ LIỆU
MÔN HỌC: NHẬP MÔN VỄ KỸ THUẬT CHƯƠNG 7: KỸ NĂNG GIẢI QUYẾT VẤN ĐỀ
Mô hình OSI và TCP/IP MẠNG MÁY TÍNH.
Nhập môn Công nghệ học Phần mềm Introduction to Software Engineering
"Đang khi cầu nguyện, diện mạo Người biến đổi khác thường".
Wireless Communications Principles and Practice
HỆ QUẢN TRỊ CƠ SỞ DỮ LIỆU SQL SERVER 2012
HƯỚNG DẪN KÍCH HOẠT TÀI KHOẢN
Nhịp & Phách (Time and Beat).
CHÚA NHẬT 3 MÙA VỌNG. C "Còn chúng tôi, chúng tôi phải làm gì?"
Hàm Lập trình nâng cao.
Bản ghi của bản thuyết trình:

Mục tiêu Ưu điểm của ADO.NET Kiến trúc của ADO.NET Kết nối DB với ADO.NET 11/15/2019 Huỳnh Phước Hải

Xây dựng App tương tác DB Khi cần xây dựng một ứng dụng cần tương tác với cơ sở dữ liệu. Có nhiều công nghệ cung cấp cho người dùng các tập hợp các đối tượng để thực hiện. 11/15/2019 Huỳnh Phước Hải

ODBC Application DataBase ODBC DriverManager 11/15/2019 Huỳnh Phước Hải

ODBC Open Data Connectivity Chỉ truy suất được các thông tin quan hệ không truy suất được các dữ liệu không quan hệ như: tập tin văn bản Email. Phải truy nhập ODBC qua DNS 11/15/2019 Huỳnh Phước Hải

DAO Application Dao MS Access Jet Engine ODBC Data Store 11/15/2019 Huỳnh Phước Hải

DAO Chỉ làm việc với Microsoft Jet Database Engine. Data Access Objects Chỉ làm việc với Microsoft Jet Database Engine. Cũng có nhiều khuyết điểm như ODBC. 11/15/2019 Huỳnh Phước Hải

Data Source Specific API OLEDB Application OLE-DB Customer OLE-DB Provider Data Store Data Source Specific API 11/15/2019 Huỳnh Phước Hải

OLEDB Để truy cập được tất cả datastore, phải dùng OLEDB provider thông qua ODBC OLEDB dễ sử dụng hơn ODBC Là một tập hợp các giao diện COM được đóng gói thành các các System Service để tương tác với nhiều DBMS 11/15/2019 Huỳnh Phước Hải

OLEDB Datasource Session Command Rowset 11/15/2019 Huỳnh Phước Hải

ADO ADO là một COM Được dùng với bất kỳ ngôn ngữ nào tương thích với COM. ADO không độc lập OS nhưng độc lập ngôn ngữ. 11/15/2019 Huỳnh Phước Hải

ADO Conection Command Recordset 11/15/2019 Huỳnh Phước Hải

ADO RDS của MS cho phép dùng ADO thông qua các giao thức HTTP. HTTPS, DCOM để truy cập dữ liệu Web. 11/15/2019 Huỳnh Phước Hải

MDAC Microsoft Data Access Components ODBC OLEDB ADO RDS 11/15/2019 Huỳnh Phước Hải

ADO.NET 11/15/2019 Huỳnh Phước Hải

Ưu điểm của ADO.NET Đáp ứng mô hình lập trình mới trên nền .NET. Hỗ trợ rất tốt SQL Server. Hỗ trợ thao tác các CSDL khác thông qua OLE DB. XML làm nền tảng. Hỗ trợ kiến trúc 3 lớp. Sử dụng namespace: System.Data, System.Xml 11/15/2019 Huỳnh Phước Hải

Kiến trúc ADO.NET 11/15/2019 Huỳnh Phước Hải

Kiến trúc ADO.NET Connected objects: là những đối tượng giao tiếp trực tiếp với CSDL. Disconnected objects: cho phép các user làm việc với dữ liệu dạng offline (khi đã đóng kết nối cơ sở dữ liệu) 11/15/2019 Huỳnh Phước Hải

Kiến trúc ADO.NET 11/15/2019 Huỳnh Phước Hải

The Managed Provider and Generic Data Set Classes To provide both connected and disconnected DB access, ADO.NET defines two sets of classes: managed provider and generic data. 11/15/2019 Huỳnh Phước Hải

The Managed Provider Classes SQL Server Managed Provider Classes. OLE DB Managed Provider Classes. ODBC Managed Provider Classes. 11/15/2019 Huỳnh Phước Hải

SQL Server Managed Provider Classes You use the SQL Server managed provider classes to connect to a SQL Server database 11/15/2019 Huỳnh Phước Hải

OLE DB Managed Provider Classes You use the OLE DB (Object Linking and Embedding for Databases) managed provider classes to connect to any database that supports OLE DB, such as Access or Oracle. 11/15/2019 Huỳnh Phước Hải

ODBC Managed Provider Classes You use the ODBC (Open Database Connectivity) managed provider classes to connect to any database that supports ODBC. All the major databases support ODBC, but ODBC is typically slower than the previous two sets of classes when working with .NET. 11/15/2019 Huỳnh Phước Hải

The Generic Data Classes The Connection Classes The Command Classes The Parameter Classes The ParameterCollection Classes The DataReader Classes The DataAdapter Classes The CommandBuilder Classes The Transaction Classes 11/15/2019 Huỳnh Phước Hải

Performing a SQL SELECT Statement and Storing the Rows Locally Formulate a string containing the details of the database connection. Create a SqlConnection object to connect to the database, passing the connection string to the constructor. Formulate a string containing a SELECT statement to retrieve the columns for the rows from the Customers table. Create a SqlCommand object to hold the SELECT statement. 11/15/2019 Huỳnh Phước Hải

Performing a SQL SELECT Statement and Storing the Rows Locally Set the CommandText property of the SqlCommand object to the SELECT string. Create a SqlDataAdapter object. Set the SelectCommand property of the SqlAdapter object to the SqlCommand object. Create a DataSet object to store the results of the SELECT statement. 11/15/2019 Huỳnh Phước Hải

Performing a SQL SELECT Statement and Storing the Rows Locally Open the database connection using the Open() method of the SqlConnection object. Call the Fill() method of the SqlDataAdapter object to retrieve the rows from the table, storing the rows locally in a DataTable of the DataSet object. Close the database connection, using the Close() method of the SqlConnection object created in step 1. Get the DataTable object from the DataSet object. Display the columns for each row in the DataTable, using a DataRow object to access each row in the DataTable. 11/15/2019 Huỳnh Phước Hải

Step 1: Formulate a String Containing the Details of the Database Connection When connecting to a SQL Server database, your string must specify the following: The name of the computer on which SQL Server is running. The name of the database. The name of the user to connect to the database as. You set this in the uid part of the string. The password for the database user. You set this in the pwd part of the string. 11/15/2019 Huỳnh Phước Hải

EX: string connectionString = "server=localhost;database=Northwind;uid=sa;pwd=sa"; String connectionstring = “ provider=Microsoft.Jet.OLEDB.4.0;" + "data source=E:\\My Course\\2009\\Lap trinh Quan Ly II\\Thuc Hanh\\ado.net\\database\\HocSinh.mdb" 11/15/2019 Huỳnh Phước Hải

Step 2: Create a SqlConnection Object to Connect to the Database Create a SqlConnection object to connect to the database, passing the connection string created in the previous step to the constructor. You use an object of the SqlConnection class to connect to a SQL Server database. EX: SqlConnection mySqlConnection = new SqlConnection(connectionString); 11/15/2019 Huỳnh Phước Hải

Step 3: Formulate a String Containing the SELECT Statement EX: Select * from HocSinh 11/15/2019 Huỳnh Phước Hải

Step 4: Create a SqlCommand Object to Hold the SELECT Statement You can call the CreateCommand() method of mySqlConnection to create a new SqlCommand object for that connection. The CreateCommand() method returns a new SqlCommand object for the SqlConnection object. EX: SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); 11/15/2019 Huỳnh Phước Hải

mySqlCommand.CommandText = selectString; Step 5: Set the CommandText Property of the SqlCommand Object to the SELECT String Set the CommandText property of your SqlCommand object to the SELECT string created in step 4. The CommandText property contains the SQL statement you want to perform. EX: mySqlCommand.CommandText = selectString; 11/15/2019 Huỳnh Phước Hải

Step 6: Create a SqlDataAdapter Object You use a SqlDataAdapter object to move information between your DataSet object and the database. You'll see how to create a DataSet object in step 8. EX: SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(); 11/15/2019 Huỳnh Phước Hải

mySqlDataAdapter.SelectCommand = mySqlCommand; Step 7: Set the SelectCommand Property of the SqlAdapter Object to the SqlCommand Object The SelectCommand property contains the SELECT statement you want to run. EX: mySqlDataAdapter.SelectCommand = mySqlCommand; 11/15/2019 Huỳnh Phước Hải

DataSet myDataSet = new DataSet(); Step 8: Create a DataSet Object to Store the Results of the SELECT Statement You use a DataSet object to store a local copy of information retrieved from the database. EX: DataSet myDataSet = new DataSet(); 11/15/2019 Huỳnh Phước Hải

EX: mySqlConnection.Open(); Step 9: Open the Database Connection Using the Open() Method of the SQLConnection Object EX: mySqlConnection.Open(); 11/15/2019 Huỳnh Phước Hải

Step 10: Call the Fill() Method of the SqlDataAdapter Object to Retrieve the Rows From the Table. EX: mySqlDataAdapter.Fill(myDataSet, "Customers"); 11/15/2019 Huỳnh Phước Hải

Step 11: Close the Database Connection Close the database connection using the Close() method of the SqlConnection object created in the first step. For example: mySqlConnection.Close(); 11/15/2019 Huỳnh Phước Hải

Step 12: Get the DataTable Object From the DataSet Object You get a DataTable from your DataSet using the Tables property, which returns a DataTableCollection object. To get an individual DataTable from your DataSet. EX: DataTable myDataTable = myDataSet.Tables["Customers"]; Note: You can also specify the DataTable you want to get by passing a numeric value to the Tables property. For example, myDataSet.Tables[0] also returns the Customers DataTable. 11/15/2019 Huỳnh Phước Hải

Step 13: Display the Columns for Each Row in the DataTable Display the columns for each row in the DataTable, using a DataRow object to access each row in the DataTable. The DataTable class defines a property named Rows that returns a DataRowCollection object containing the DataRow objects stored in that DataTable. EX: foreach (DataRow myDataRow in myDataTable.Rows) { // ... access the myDataRow object } foreach (DataRow myDataRow in myDataTable.Rows) { Console.WriteLine("CustomerID = "+ myDataRow["CustomerID"]); Console.WriteLine("CompanyName = "+ myDataRow["CompanyName"]); Console.WriteLine("ContactName = "+ myDataRow["ContactName"]); Console.WriteLine("Address = "+ myDataRow["Address"]); } 11/15/2019 Huỳnh Phước Hải

EX Full Demo. Connect Step For Step 11/15/2019 Huỳnh Phước Hải