Module  9: Accessing Relational Data Using Microsoft Visual Studio .NET
Overview <ul><li>Overview of ADO.NET </li></ul><ul><li>Creating a Connection to a Database </li></ul><ul><li>Displaying a ...
Lesson: Overview of ADO.NET <ul><li>What is ADO.NET? </li></ul><ul><li>Using Namespaces </li></ul><ul><li>The ADO.NET Obje...
What is ADO.NET? ADO.NET provides a set of classes for working with data. ADO.NET provides: <ul><li>An evolutionary, more ...
Using Namespaces <ul><li>Use the Imports or using statement to import namespaces </li></ul><ul><li>Namespaces used with AD...
The ADO.NET Object Model DataSet SQL Server .NET  Data Provider OLE DB .NET  Data Provider SQL Server 7.0 (and later) OLED...
What is a Dataset? SQL Server 2000 DataSet DataTable DataTable Physical storage OleDb Database SqlDataAdapter SqlConnectio...
Accessing Data with ADO.NET Database <ul><li>Return the DataSet to the Client </li></ul><ul><li>Client manipulates the dat...
Practice: Identifying ADO.NET Components <ul><li>Students will: </li></ul><ul><ul><li>Move icons of various components of ...
Lesson: Creating a Connection to a Database <ul><li>Using Server Explorer to Generate a Connection </li></ul><ul><li>The D...
Using Server Explorer to Generate a Connection <ul><li>Create a new data connection by dragging a Table from Server Explor...
The DataAdapter Object Model sp_SELECT Command SelectCommand UpdateCommand InsertCommand DeleteCommand DataAdapter Command...
Demonstration: Connecting to a Database <ul><li>Expand Server Explorer to a table in a SQL Server database </li></ul><ul><...
Generating a DataSet <ul><li>You can generate a DataSet… </li></ul><ul><ul><li>… through the UI… </li></ul></ul><ul><ul><u...
Demonstration: Generating a DataSet <ul><li>Create a typed DataSet from a DataAdapter </li></ul><ul><li>Add a second DataT...
Lesson: Displaying a DataSet in a List-Bound Control <ul><li>What are List-Bound Controls? </li></ul><ul><li>Displaying Da...
What are List-Bound Controls? <ul><li>Controls that connect to a data source and display the data </li></ul><ul><li>List-b...
Displaying DataSet Data in List-Bound Controls <ul><li>Set the properties </li></ul><ul><li>Fill the DataSet, then call th...
Demonstration: Binding List-Bound Controls to a Database <ul><li>Add a DataGrid to a Web Form </li></ul><ul><li>Set the Da...
Practice: Using a DataGrid <ul><li>Students will: </li></ul><ul><ul><li>Create a  SqlConnection </li></ul></ul><ul><ul><li...
Demonstration: Customizing the DataGrid Control <ul><li>Using AutoFormat </li></ul><ul><li>Setting custom column headers <...
Review <ul><li>Overview of ADO.NET </li></ul><ul><li>Creating a Connection to a Database </li></ul><ul><li>Displaying a Da...
Lab 9: Accessing Relational Data Using Microsoft Visual Studio .NET Medical Medical.aspx Benefits Home Page Default.aspx L...
Upcoming SlideShare
Loading in...5
×

2310 b 09

914

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
914
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
81
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

2310 b 09

  1. 1. Module 9: Accessing Relational Data Using Microsoft Visual Studio .NET
  2. 2. Overview <ul><li>Overview of ADO.NET </li></ul><ul><li>Creating a Connection to a Database </li></ul><ul><li>Displaying a DataSet in a List-Bound Control </li></ul>
  3. 3. Lesson: Overview of ADO.NET <ul><li>What is ADO.NET? </li></ul><ul><li>Using Namespaces </li></ul><ul><li>The ADO.NET Object Model </li></ul><ul><li>What is a DataSet? </li></ul><ul><li>Accessing Data with ADO.NET </li></ul><ul><li>Practice: Identifying ADO.NET Components </li></ul>
  4. 4. What is ADO.NET? ADO.NET provides a set of classes for working with data. ADO.NET provides: <ul><li>An evolutionary, more flexible successor to ADO </li></ul><ul><li>A system designed for disconnected environments </li></ul><ul><li>A programming model with advanced XML support </li></ul><ul><li>A set of classes, interfaces, structures, and enumerations that manage data access from within the .NET Framework </li></ul>
  5. 5. Using Namespaces <ul><li>Use the Imports or using statement to import namespaces </li></ul><ul><li>Namespaces used with ADO.NET include: </li></ul><ul><ul><li>System.Data </li></ul></ul><ul><ul><li>System.Data.SqlClient </li></ul></ul><ul><ul><li>System.Data.OleDb </li></ul></ul>Imports System.Data Imports System.Data.SqlClient using System.Data; using System.Data.SqlClient;
  6. 6. The ADO.NET Object Model DataSet SQL Server .NET Data Provider OLE DB .NET Data Provider SQL Server 7.0 (and later) OLEDB sources (SQL Server 6.5) OleDbConnection OleDbDataAdapter SqlDataAdapter SqlConnection DataTable DataTable
  7. 7. What is a Dataset? SQL Server 2000 DataSet DataTable DataTable Physical storage OleDb Database SqlDataAdapter SqlConnection DataTable Web server memory OleDbDataAdapter OleDbConnection
  8. 8. Accessing Data with ADO.NET Database <ul><li>Return the DataSet to the Client </li></ul><ul><li>Client manipulates the data </li></ul><ul><li>Create the SqlConnection and SqlDataAdapter objects </li></ul><ul><li>Fill the DataSet from the DataAdapter and close the connection </li></ul>SqlDataAdapter SqlConnection List-Bound Control <ul><li>Client makes request </li></ul>1 2 3 4 5 <ul><li>Update the DataSet </li></ul><ul><li>Use the SqlDataAdapter to open the SqlConnection, update the database, and close the connection </li></ul>6 7 Client Web server DataSet
  9. 9. Practice: Identifying ADO.NET Components <ul><li>Students will: </li></ul><ul><ul><li>Move icons of various components of ADO.NET to the correct locations </li></ul></ul><ul><li>Time: 5 Minutes </li></ul>
  10. 10. Lesson: Creating a Connection to a Database <ul><li>Using Server Explorer to Generate a Connection </li></ul><ul><li>The DataAdapter Object Model </li></ul><ul><li>Demonstration: Connecting to a Database </li></ul><ul><li>Generating a DataSet </li></ul><ul><li>Demonstration: Generating a DataSet </li></ul>
  11. 11. Using Server Explorer to Generate a Connection <ul><li>Create a new data connection by dragging a Table from Server Explorer </li></ul><ul><li>Create a new data connection using the Data Links dialog box </li></ul>
  12. 12. The DataAdapter Object Model sp_SELECT Command SelectCommand UpdateCommand InsertCommand DeleteCommand DataAdapter Command Command Command Connection sp_UPDATE sp_INSERT sp_DELETE Database DataSet DataReader
  13. 13. Demonstration: Connecting to a Database <ul><li>Expand Server Explorer to a table in a SQL Server database </li></ul><ul><li>Drag the table to an ASP.NET Web Form </li></ul><ul><li>View the data using the SqlDataAdapter </li></ul><ul><li>View the source of the page that was created </li></ul><ul><li>Configure the DataAdapter object </li></ul>
  14. 14. Generating a DataSet <ul><li>You can generate a DataSet… </li></ul><ul><ul><li>… through the UI… </li></ul></ul><ul><ul><ul><li>Creates a DataSet that allows you to access data as an object </li></ul></ul></ul><ul><ul><li>… or through code… </li></ul></ul><ul><li>and then fill… </li></ul>Dim ds As New DataSet() DataAdapter1.Fill(ds) DataAdapter2.Fill(ds) DataSet ds = new DataSet(); DataAdapter1.Fill(ds); DataAdapter2.Fill(ds);
  15. 15. Demonstration: Generating a DataSet <ul><li>Create a typed DataSet from a DataAdapter </li></ul><ul><li>Add a second DataTable from a different DataAdapter </li></ul><ul><li>Show the schema of DataSet </li></ul>
  16. 16. Lesson: Displaying a DataSet in a List-Bound Control <ul><li>What are List-Bound Controls? </li></ul><ul><li>Displaying DataSet Data in List-Bound Controls </li></ul><ul><li>Demonstration: Binding List-Bound Controls to a Database </li></ul><ul><li>Practice: Using a DataGrid </li></ul><ul><li>Demonstration: Customizing the DataGrid Control </li></ul>
  17. 17. What are List-Bound Controls? <ul><li>Controls that connect to a data source and display the data </li></ul><ul><li>List-bound controls include the following: </li></ul><ul><ul><li>DropDownList </li></ul></ul><ul><ul><li>ListBox </li></ul></ul><ul><ul><li>CheckBoxList </li></ul></ul><ul><ul><li>RadioButtonList </li></ul></ul><ul><ul><li>DataGrid </li></ul></ul><ul><ul><li>DataList </li></ul></ul><ul><ul><li>Repeater </li></ul></ul>
  18. 18. Displaying DataSet Data in List-Bound Controls <ul><li>Set the properties </li></ul><ul><li>Fill the DataSet, then call the DataBind method </li></ul>DataAdapter1.Fill(ds) lstEmployees.DataBind() DataAdapter1.Fill(ds); lstEmployees.DataBind(); Property Description DataSource <ul><li>The DataSet containing the data </li></ul>DataMember <ul><li>The DataTable in the DataSet </li></ul>DataTextField <ul><li>The field in the DataTable that is displayed </li></ul>DataValueField <ul><li>The field in the DataTable that becomes the value of the selected item in the list </li></ul>
  19. 19. Demonstration: Binding List-Bound Controls to a Database <ul><li>Add a DataGrid to a Web Form </li></ul><ul><li>Set the DataSource and DataMember properties </li></ul><ul><li>Fill the DataSet </li></ul><ul><li>Call DataBind() </li></ul>
  20. 20. Practice: Using a DataGrid <ul><li>Students will: </li></ul><ul><ul><li>Create a SqlConnection </li></ul></ul><ul><ul><li>Create a SqlDataAdapter </li></ul></ul><ul><ul><li>Generate a DataSet </li></ul></ul><ul><ul><li>Place a DataGrid on a Web Form </li></ul></ul><ul><ul><li>Bind the DataGrid to the DataSet </li></ul></ul><ul><li>Time: 5 minutes </li></ul>
  21. 21. Demonstration: Customizing the DataGrid Control <ul><li>Using AutoFormat </li></ul><ul><li>Setting custom column headers </li></ul><ul><li>Paging </li></ul><ul><li>Sorting </li></ul>
  22. 22. Review <ul><li>Overview of ADO.NET </li></ul><ul><li>Creating a Connection to a Database </li></ul><ul><li>Displaying a DataSet in a List-Bound Control </li></ul>
  23. 23. Lab 9: Accessing Relational Data Using Microsoft Visual Studio .NET Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web Service dentalService1.asmx Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu Component Class1.vb or Class1.cs XML Files Web. config
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×