Module 2 Using ADO NET to Access Data
- Slides: 30
Module 2: Using ADO. NET to Access Data
Overview n ADO. NET Architecture n Creating an Application That Uses ADO. NET to Access Data n Changing Database Records
Lesson: ADO. NET Architecture n What Is ADO. NET? n What Is a Connected Environment? n What Is a Disconnected Environment? n What Is the ADO. NET Object Model? n What Is the Data. Set Class? n What Is the. NET Data Provider?
What Is ADO. NET? ADO. NET is a data access technology. It provides: n A set of classes, interfaces, structures, and enumerations that manage data access from within the. NET Framework n An evolutionary, more flexible successor to ADO n A system designed for disconnected environments n A programming model with advanced XML support
What Is a Connected Environment? n A connected environment is one in which users are constantly connected to a data source n Advantages: n l Environment is easier to secure l Concurrency is more easily controlled l Data is more likely to be current than in other scenarios Disadvantages: l Must have a constant network connection l Scalability
What Is a Disconnected Environment? n In a disconnected environment, a subset of data from a central data store can be copied and modified independently, and the changes merged back into the central data store n Advantages l You can work at any time that is convenient for you, and can connect to a data source at any time to process requests l Other users can use the connection l A disconnected environment improves the scalability and performance of applications n Disadvantages l Data is not always up to date l Change conflicts can occur and must be resolved
What Is the ADO. NET Object Model? Data. Set. NET Data Provider Connection Transaction Command Data. Adapter Select. Command Insert. Command Parameters Update. Command Data. Reader Delete. Command Data. Table. Collection Data. Table Data. Row. Collection Data. Column. Collection Constraint. Collection Data. Relation. Collection XML Database
Multimedia: Using ADO. NET to Access Data
What Is the Data. Set Class? Data. Set n Tables Table Data. Sets consist of one or more tables and relations l Loaded from one or more data adapters l Created as you work l Loaded from XML l Loaded from other Data. Sets Column Constraints Constraint Rows n Row Relations Tables contain columns, constraints, and rows l Relation Object All are collections! Collection
What Is the. NET Data Provider? Database Connection Manages the connection to a database Executes a query command on the database Command Data. Adapter Data. Reader Exchanges data between the data set and the database Provides efficient access to a stream of read-only data
Practice: ADO. NET Architecture Matching Practice 10 min
Lesson: Creating an Application That Uses ADO. NET to Access Data n How to Specify the Database Connection n How to Specify the Database Command n How to Create the Data. Adapter Object n How to Create a Data. Set Object n How to Bind a Data. Set to a Data. Grid n How to Use the Data Wizards in Visual Studio. NET
How to Specify the Database Connection n n Use the Connection object to: l Choose the connection type l Specify the data source l Open the connection to the data source Use the connection string to specify all of the options for your connection to the database, including the account name, database server, and database name string connection. Str = @"Data Source=localhost; Integrated Security=SSPI; Initial Catalog=northwind";
How to Specify the Database Command string command. Str=@"SELECT Customer. Name, Company. Name FROM Customers"; n Create a string containing SQL statements l n Remember that Verbatim strings can make this much easier! Examples of SQL statements: l SELECT * FROM Customers l SELECT Customer. Name FROM Customers l SELECT * FROM Customers WHERE Country = 'Mexico'
How to Create the Data. Adapter Object Data. Set Data source Data. Adapter Data. Table Fill Update
How to Create a Data. Set Object Data. Set n Use Fill method of Data. Adapter n Populate programmatically by creating a table structure and filling it n Read an XML document or stream into a Data. Set n Use Merge method to copy the contents of another Data. Set object Tables Table Columns Column Constraints Constraint Rows Row Relations Relation Object Collection
How to Bind a Data. Set to a Data. Grid n To bind programmatically Data. Grid data. Grid 1 = new Data. Grid(); sql. Data. Adapter 1. Fill(data. Set 1, "Customers"); sql. Data. Adapter 2. Fill(data. Set 1, "Orders"); data. Grid 1. Data. Source = data. Set 1;
Demonstration: Using the Data Wizards in Visual Studio. NET n In instructor-led demonstration will show you how to use the Data Adapter Configuration Wizard, how to use the Server Explorer, and how to use the Data Form Wizard
How to Use the Data Wizards in Visual Studio. NET
Practice: Using the Data Adapter Configuration Wizard Guided Practice n In this practice you will add a new database record to the Shippers table in the Northwind Traders database n You will use the Data Adapter Configuration Wizard in Visual Studio. NET to generate most of the code 10 min
Lesson: Changing Database Records n How to Access Data in a Data. Set Object n How to Update a Database in ADO. NET n How to Create a Database Record n How to Update a Database Record n How to Delete a Database Record
How to Access Data in a Data. Set Object Data. Row objects Data. Table objects Data. Column objects
How to Update a Database in ADO. NET Client Server Data. Adapter Data. Set Database Fill Update Data. Table Insert. Command Update. Command Delete. Command
How to Create a Database Record n Create a new row that matches the table schema Data. Row my. Row = data. Table. New. Row(); n Add the new row to the dataset data. Table. Rows. Add( my. Row ); n Update the database sql. Data. Adapter 1. Update( data. Set );
How to Update a Database Record Modify the row containing the record Generate a new dataset containing the changes Check the new dataset for errors Merge the changes back into the original dataset Call the Update method on the data adapter Call the Accept. Changes method on your original dataset
How to Delete a Database Record n Delete the row from the dataset data. Table. Rows[0]. Delete(); n Update the database data. Adapter. Update(data. Set); n Accept the changes to the dataset data. Set. Accept. Changes();
Practice: Updating a Database Record Guided Practice n In this practice, you will create and delete a database record, experimenting with the Update, Accept. Changes and Reject. Changes methods 10 min
Review n ADO. NET Architecture n Creating an Application That Uses ADO. NET to Access Data n Changing Database Records
Lab 7. 1: Creating a Data Access Application with ADO. NET n Exercise 1: Creating a simple database table viewer n Exercise 2: Writing a Simple Database Table Viewer n Exercise 3 (if time permits): Creating a simple database viewer 1 hour
Lab 7. 2 (optional): Creating a Windows Application That Uses ADO. NET n Exercise 1: Creating a Windows Application that uses ADO. NET n Exercise 2 (if time permits): Writing an ADO. NET Application with Windows Forms 1 hour
- Ado.net vb.net
- Access vba ado
- Executereader
- Ado.net object model
- ¿qué es ado.net?
- What are the ado.net objectives
- Ado.net object model
- Ado.net stands for
- Ado net rest
- Describe about ado objects
- Linq vs ado.net
- Ado.net overview
- Ado net active directory
- Ado.net diagram
- Async ado.net
- Sqlite ppt
- Ado.net c
- C device module module 1
- Access module 2: querying a database
- Access module 3 maintaining a database
- Access module 2 querying a database
- Shared computing cluster
- Troubleshooting
- Terminal access controller access control system plus
- Terminal access controller access-control system
- Perimeter formula
- Module 10 coordinate proof using slope
- Code access security in .net
- Tsupino
- Conceito de verbo
- Much ado about nothing allusions