2310 b 09
Post on 20-Jan-2015
872 Views
Preview:
DESCRIPTION
TRANSCRIPT
Module 9:Accessing Relational Data Using Microsoft Visual Studio .NET
Overview
Overview of ADO.NET
Creating a Connection to a Database
Displaying a DataSet in a List-Bound Control
Lesson: Overview of ADO.NET
What is ADO.NET?
Using Namespaces
The ADO.NET Object Model
What is a DataSet?
Accessing Data with ADO.NET
Practice: Identifying ADO.NET Components
ADO.NET provides a set of classes for working with data. ADO.NET provides:
An evolutionary, more flexible successor to ADO
A system designed for disconnected environments
A programming model with advanced XML support
A set of classes, interfaces, structures, and enumerations that manage data access from within the .NET Framework
What is ADO.NET?
Using Namespaces
Use the Imports or using statement to import namespaces
Namespaces used with ADO.NET include:
System.Data
System.Data.SqlClient
System.Data.OleDb
Imports System.DataImports System.Data.SqlClientImports System.DataImports System.Data.SqlClient
using System.Data;using System.Data.SqlClient;using System.Data;using System.Data.SqlClient;
DataSet
SQL Server .NET Data Provider
OLE DB .NET Data Provider
SQL Server 7.0(and later)
OLEDB sources(SQL Server 6.5)
OleDbConnectionOleDbConnection
OleDbDataAdapterOleDbDataAdapterSqlDataAdapterSqlDataAdapter
SqlConnectionSqlConnection
DataTable
DataTable
The ADO.NET Object Model
SQL Server 2000
DataSet
DataTable
DataTable
Physical storage
OleDb Database
SqlDataAdapterSqlDataAdapter
SqlConnectionSqlConnection
DataTable
Web server memory
OleDbDataAdapterOleDbDataAdapter
OleDbConnection
OleDbConnection
What is a Dataset?
Accessing Data with ADO.NET
DatabaseDatabase
4. Return the DataSet to the Client
5. Client manipulates the data
2. Create the SqlConnection and SqlDataAdapter objects
3. Fill the DataSet from the DataAdapter and close the connection
SqlDataAdapter
SqlConnection
List-Bound
Control
List-Bound
Control
1. Client makes request1111
2222
3333
4444
5555
6. Update the DataSet
7. Use the SqlDataAdapter to open the SqlConnection, update the database, and close the connection
6666
7777
ClientClient
Web serverWeb server
DataSet
Practice: Identifying ADO.NET Components
Students will:
Move icons of various components of ADO.NET to the correct locations
Time: 5 Minutes
Lesson: Creating a Connection to a Database
Using Server Explorer to Generate a Connection
The DataAdapter Object Model
Demonstration: Connecting to a Database
Generating a DataSet
Demonstration: Generating a DataSet
Using Server Explorer to Generate a Connection
Create a new data connection by dragging a Table from Server Explorer
Create a new data connection using the Data Links dialog box
The DataAdapter Object Model
sp_SELECT
CommandCommand
SelectCommand UpdateCommand InsertCommand DeleteCommand
DataAdapter
CommandCommand CommandCommand CommandCommand
ConnectionConnection
sp_UPDATE sp_INSERT sp_DELETE
Database
DataSetDataSet
DataReaderDataReader
Demonstration: Connecting to a Database
Expand Server Explorer to a table in a SQL Server database
Drag the table to an ASP.NET Web Form
View the data using the SqlDataAdapter
View the source of the page that was created
Configure the DataAdapter object
Generating a DataSet
You can generate a DataSet…
…through the UI…Creates a DataSet that allows you to access
data as an object
…or through code…
and then fill…
Dim ds As New DataSet()Dim ds As New DataSet()
DataAdapter1.Fill(ds)DataAdapter2.Fill(ds)DataAdapter1.Fill(ds)DataAdapter2.Fill(ds)
DataSet ds = new DataSet();DataSet ds = new DataSet();
DataAdapter1.Fill(ds);DataAdapter2.Fill(ds);DataAdapter1.Fill(ds);DataAdapter2.Fill(ds);
Demonstration: Generating a DataSet
Create a typed DataSet from a DataAdapter
Add a second DataTable from a different DataAdapter
Show the schema of DataSet
Lesson: Displaying a DataSet in a List-Bound Control
What are List-Bound Controls?
Displaying DataSet Data in List-Bound Controls
Demonstration: Binding List-Bound Controls to a Database
Practice: Using a DataGrid
Demonstration: Customizing the DataGrid Control
What are List-Bound Controls?
Controls that connect to a data source and display the data
List-bound controls include the following:
DropDownList
ListBox
CheckBoxList
RadioButtonList
DataGrid
DataList
Repeater
Displaying DataSet Data in List-Bound Controls
Set the properties
Fill the DataSet, then call the DataBind methodDataAdapter1.Fill(ds)lstEmployees.DataBind()DataAdapter1.Fill(ds)lstEmployees.DataBind()
PropertyPropertyPropertyProperty DescriptionDescriptionDescriptionDescription
DataSourceDataSource The DataSet containing the data The DataSet containing the data
DataMemberDataMember The DataTable in the DataSet The DataTable in the DataSet
DataTextFieldDataTextField The field in the DataTable that is displayed The field in the DataTable that is displayed
DataValueFieldDataValueField The field in the DataTable that becomes the value of the selected item in the list
The field in the DataTable that becomes the value of the selected item in the list
DataAdapter1.Fill(ds);lstEmployees.DataBind();DataAdapter1.Fill(ds);lstEmployees.DataBind();
Demonstration: Binding List-Bound Controls to a Database
Add a DataGrid to a Web Form
Set the DataSource and DataMember properties
Fill the DataSet
Call DataBind()
Practice: Using a DataGrid
Students will:
Create a SqlConnection
Create a SqlDataAdapter
Generate a DataSet
Place a DataGrid on a Web Form
Bind the DataGrid to the DataSet
Time: 5 minutes
Demonstration: Customizing the DataGrid Control
Using AutoFormat
Setting custom column headers
Paging
Sorting
Review
Overview of ADO.NET
Creating a Connection to a Database
Displaying a DataSet in a List-Bound Control
MedicalMedical.aspxMedicalMedical.aspx
BenefitsHome PageDefault.aspx
BenefitsHome PageDefault.aspx
Life InsuranceLife.aspxLife InsuranceLife.aspx
RetirementRetirement.aspxRetirementRetirement.aspx
DentalDental.aspxDentalDental.aspx
Dentists
DoctorsDoctors.aspx DoctorsDoctors.aspx
Doctors
Logon PageLogin.aspxLogon PageLogin.aspx
RegistrationRegister.aspxRegistrationRegister.aspx
CohoWinery
ProspectusProspectus.aspxProspectusProspectus.aspx
XML Web ServicedentalService1.asmx
XML Web ServicedentalService1.asmx
Page HeaderHeader.ascxPage HeaderHeader.ascx
ASPState
tempdb
Lab Web Application
User Controlnamedate.ascxUser Controlnamedate.ascx
Menu ComponentClass1.vb or Class1.cs
Menu ComponentClass1.vb or Class1.cs
XML Files
Web.config
Lab 9: Accessing Relational Data Using Microsoft Visual Studio .NET
top related