Is2215 lecture7 lecturer_ado_intro

41
ADO.NET DATABASES IN VISUAL BASIC.NET

description

 

Transcript of Is2215 lecture7 lecturer_ado_intro

Page 1: Is2215 lecture7 lecturer_ado_intro

ADO.NETDATABASES IN VISUAL BASIC.NET

Page 2: Is2215 lecture7 lecturer_ado_intro

ADO .NET

ADO.NET is an OO framework that allows you to interact with DBs

Can use ADO.NET through code, or by using bounded controls

ADO.NET extremely flexible and efficient

Page 3: Is2215 lecture7 lecturer_ado_intro

ADO.NET

Previously applications would talk to Database using SQL

The application would be constantly connected to the DB

We still use SQL but the data is disconnected

It will connect to a database server when it needs to run a query and then disconnects immediately

ADO.NET still provides the connection oriented traditional approach.

Page 4: Is2215 lecture7 lecturer_ado_intro

Traditional Data Access Architecture

1. Makes a Connection 2. Pass some query to DB and reads

result3. Pass another query to DB and reads

result4. Disconnects from DB System

Page 5: Is2215 lecture7 lecturer_ado_intro

ADO.NET Disconnected Model1. Make a connection2. Pass query and gets back result3. Disconnects4. Makes connection again5. Passes another query and gets

result6. Disconnects from the DB

Page 6: Is2215 lecture7 lecturer_ado_intro

ADO.NET

Keeps a local virtual copy of the database in your application

All of the generic classes for data access are stored in the System.Data Namespace.

Page 7: Is2215 lecture7 lecturer_ado_intro

ADO.NET

ADO.NET uses managed providers to connect to databases

Managed providers allow fast data streams from databases

Deals with security such as database locks, passwords etc.,

Page 8: Is2215 lecture7 lecturer_ado_intro

Main Components of ADO.NETObject Description

Connection Creates a connection to the data source

Command Provides access to commands that can be executed against the data source

DataAdapter Serves as an ambassador between your dataset and datasource, maps instructions between the two

DataSet Provides an in-memory representation of your data source

DataReader Read-Only forward stream containing your data

Page 9: Is2215 lecture7 lecturer_ado_intro

Advantages

Interoperability Data is transported as XML Can be read by anyone on any platform

Scalability Client Server model is gone ADO promotes the use of disconnected

datasets Productivity

Quicker Less Bugs

Page 10: Is2215 lecture7 lecturer_ado_intro

Advantages Cont’d

Performance Disconnected datasets Database Server is no longer a bottleneck Performance boost Concurrency Database not locked out all the time

Page 11: Is2215 lecture7 lecturer_ado_intro

Using ADO.NET in Code

1. Set up your objects2. Connect to DB using connection

object3. Set up the data adapter 4. Copy data from data adapter to

Dataset

Page 12: Is2215 lecture7 lecturer_ado_intro
Page 13: Is2215 lecture7 lecturer_ado_intro

USING ADO.NET WITH ACCESS DB

Connecting to a DB in Code

Page 14: Is2215 lecture7 lecturer_ado_intro

A Simple DB Application

Page 15: Is2215 lecture7 lecturer_ado_intro

Code Cont’d

Page 16: Is2215 lecture7 lecturer_ado_intro

Code Cont’d

Page 17: Is2215 lecture7 lecturer_ado_intro

Code Cont’d

Page 18: Is2215 lecture7 lecturer_ado_intro

Doing it In Code

An access Database Table It will be represented in our DataSet as

a Table The first table is given an index of 0 The first row in the table has an index

value of 0 also The first column has a value of 0

Page 19: Is2215 lecture7 lecturer_ado_intro
Page 20: Is2215 lecture7 lecturer_ado_intro

Code Cont’d

Page 21: Is2215 lecture7 lecturer_ado_intro

The Code

Set up the objects

Page 22: Is2215 lecture7 lecturer_ado_intro
Page 23: Is2215 lecture7 lecturer_ado_intro

The Code

Set up the objects

Page 24: Is2215 lecture7 lecturer_ado_intro
Page 25: Is2215 lecture7 lecturer_ado_intro

The Code

Set up the objects

Page 26: Is2215 lecture7 lecturer_ado_intro
Page 27: Is2215 lecture7 lecturer_ado_intro

The Code

Set up the objects

Page 28: Is2215 lecture7 lecturer_ado_intro
Page 29: Is2215 lecture7 lecturer_ado_intro

The Code

Set up the objects

Page 30: Is2215 lecture7 lecturer_ado_intro
Page 31: Is2215 lecture7 lecturer_ado_intro

The Code

Fill the DataSet using the DataAdapter

Page 32: Is2215 lecture7 lecturer_ado_intro

The Code – Displaying the DataSet Contents

Point a textbox to a row and column of the dataset Table

Point a DataGrid control at a DataSet

................................................................................

..........................

Page 33: Is2215 lecture7 lecturer_ado_intro

The Code: Counting the Number of Rows

Page 34: Is2215 lecture7 lecturer_ado_intro

Point a textbox to a row and column of the dataset Table

Point a DataGrid control at a DataSet

................................................................................

..........................

Page 35: Is2215 lecture7 lecturer_ado_intro

Customising the Generic Code

Page 36: Is2215 lecture7 lecturer_ado_intro

Set Up the Objects

Page 37: Is2215 lecture7 lecturer_ado_intro

The Form Load Code

Page 38: Is2215 lecture7 lecturer_ado_intro

The UpdateTextBoxes Sub Procedure

Page 39: Is2215 lecture7 lecturer_ado_intro

Navigation Code: Previous Record

Page 40: Is2215 lecture7 lecturer_ado_intro

Navigation Code: Next Record

Page 41: Is2215 lecture7 lecturer_ado_intro

Navigation Code: Find Record