+ All Categories
Home > Technology > 2310 b 09

2310 b 09

Date post: 20-Jan-2015
Category:
Upload: krazy-koder
View: 871 times
Download: 1 times
Share this document with a friend
Description:
 
Popular Tags:
23
Module 9: Accessing Relational Data Using Microsoft Visual Studio .NET
Transcript
Page 1: 2310 b 09

Module 9:Accessing Relational Data Using Microsoft Visual Studio .NET

Page 2: 2310 b 09

Overview

Overview of ADO.NET

Creating a Connection to a Database

Displaying a DataSet in a List-Bound Control

Page 3: 2310 b 09

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

Page 4: 2310 b 09

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?

Page 5: 2310 b 09

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;

Page 6: 2310 b 09

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

Page 7: 2310 b 09

SQL Server 2000

DataSet

DataTable

DataTable

Physical storage

OleDb Database

SqlDataAdapterSqlDataAdapter

SqlConnectionSqlConnection

DataTable

Web server memory

OleDbDataAdapterOleDbDataAdapter

OleDbConnection

OleDbConnection

What is a Dataset?

Page 8: 2310 b 09

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

Page 9: 2310 b 09

Practice: Identifying ADO.NET Components

Students will:

Move icons of various components of ADO.NET to the correct locations

Time: 5 Minutes

Page 10: 2310 b 09

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

Page 11: 2310 b 09

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

Page 12: 2310 b 09

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

Page 13: 2310 b 09

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

Page 14: 2310 b 09

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);

Page 15: 2310 b 09

Demonstration: Generating a DataSet

Create a typed DataSet from a DataAdapter

Add a second DataTable from a different DataAdapter

Show the schema of DataSet

Page 16: 2310 b 09

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

Page 17: 2310 b 09

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

Page 18: 2310 b 09

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();

Page 19: 2310 b 09

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()

Page 20: 2310 b 09

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

Page 21: 2310 b 09

Demonstration: Customizing the DataGrid Control

Using AutoFormat

Setting custom column headers

Paging

Sorting

Page 22: 2310 b 09

Review

Overview of ADO.NET

Creating a Connection to a Database

Displaying a DataSet in a List-Bound Control

Page 23: 2310 b 09

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


Recommended