1 / 13

ADO.NET

ADO.NET. NỘI DUNG. Mô hình công nghệ Data Control ADO.NET DataSet DataTable DataColumn DataRow DataView Data Provider Connection Command DataAdapter. MÔ HÌNH. DataSet DataTable DataRow DataColumn. SELECT. UI Control. DataSet. Data Provider. DataSource. DataAdapter. DB

nat
Download Presentation

ADO.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ADO.NET

  2. NỘI DUNG • Môhìnhcôngnghệ • Data Control • ADO.NET • DataSet • DataTable • DataColumn • DataRow • DataView • Data Provider • Connection • Command • DataAdapter

  3. MÔ HÌNH DataSet DataTable DataRow DataColumn SELECT UI Control DataSet Data Provider DataSource DataAdapter DB (SQL Server) User ADO.NET Connection Command DataAdapter DataReader INSERT, UPDATE, DELETE DataGridView ComboBox ListBox

  4. DATA CONTROL • DropDownList, ListBox, CheckBoxList, RadioButtonList • DataSource • DataTextFiled • DataValueField • DataBind() • GridView, DataList, FormView, DetailView • DataSource • DataBind()

  5. DATA BINDINGS • Kết nối với GridView • gridView.DataSource = dataTable; • gridView.DataBind(); • Kết nối với DropDownList • ddl.DataSource = dataTable; • ddl.DataTextFiled = "HoTen"; • ddl.DataValueField = "MaNV"; • ddl.DataBind();

  6. DATA PROVIDER • Connection: kết nối đến CSDL • SqlConnection, OleDbConnection… • Command: mang câu lệnh cần thực thi • SqlCommand, OleDbCommand… • DataAdapter: truy vấn dữ liệu từ CSDL và ghép nối với data table • SqlDataAdapter, OleDbDataAdapter… • DataReader: truy vấn dữ liệu (ít dùng) • SqlDataReader, OleDbDataReader…

  7. CONNECTION • Thiết lập chuỗi kết nối • String connectionString1 = "Data Source=.; Initial Catalog=QuanLyBanHang; Integrated Security=True"; • String connectionString 2= “Server=.; Database=QuanLyBanHang; User Id=sa; Password=sa"; • Tạo đối tượng kết nối • SqlConnection connection = new SqlConnection(connectionString);

  8. SQL 2008 ConnectionString • Theo đặc quyền của SQL Server (có user, pass): server= HIENLTH-PC; database = QLHS; user id=sa; password=sa • Theo đặc quyền của hệ điều hành: server= HIENLTH-PC; database = QLHS; Trusted Connection = True; server= HIENLTH-PC; database = QLHS; Integrated Security = True;

  9. COMMAND • Thao tác dữ liệu (INSERT, UPDATE, DELETE) • String sql = “INSERT INTO TableName(C1, C2, C3) VALUES(‘???’, ‘???’, ‘???’)”; • Thực thi câu lệnh • SqlCommand command = new SqlCommand(sql, connection); • command.Connection.Open(); • int rows = Command.ExecuteNonQuery(); • command.Connection.Close();

  10. VÍ DỤ

  11. VÍ DỤ

  12. ADO.NET • Phần ngắt kết nối: là DataSet • DataSet không quan tâm đến Database thuộc kiểu gì, và lấy dữ liệu từ DataAdapter để xử lý • DataSet xem như một Database trong bộ nhớ: bảng, quan hệ… • DataSet có các thành phần con như • DataTable • DataRow • DataColumn • DataRelation • Các đối tượng nhóm: DataTableCollection, DataRowCollection, DataColumnCollection

  13. DATA ADAPTER • Truy vấn dữ liệu (SELECT) và ghép nối với data table • String sql = “SELECT * FROM T WHERE…”; • Truy vấn dữ liệu và đổ dữ liệu vào DataTable • SqlDataAdapter adapter = new SqlDataAdapter (sql, connection); • DataTable table = new DataTable(); • adapter.Fill(table);

More Related