0% found this document useful (0 votes)
32 views26 pages

JK VB Net 9 Database Ado

Jk Vb Net 9 Database Ado

Uploaded by

curtisandrea242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views26 pages

JK VB Net 9 Database Ado

Jk Vb Net 9 Database Ado

Uploaded by

curtisandrea242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Working With Databases

Introduction
 Basic database terminology
 Fundamental database concepts
 Use ADO .NET to access databases
 Use the DataGridView control
 Documenting your code
Database Management
1 Systems

Visual Basic applications use database


management systems to make large
amounts of data available to programs
Visual Basic and Database
Management Systems
 Simple text files
 Fine for small amounts of data

 But impractical for large amounts of data

 Businesses must maintain huge amounts of data


 A database management system (DBMS) is the

typical solution to the data needs of business


 Designed to store, retrieve, & manipulate data

 Visual Basic can communicate with a DBMS


 Tells DBMS what data to retrieve or manipulate
Layered Approach to Using a DBMS
 Applications that work with a
DBMS use a layered approach
 VB application is topmost layer

 VB sends instructions to next

layer, the DBMS


 DBMS works directly with data

 Programmer need not understand


the physical structure of the data
 Just need to know how to

interact with the database


Visual Basic Supports Many DBMS’s
 Visual Basic can interact with many DBMS’s
 Microsoft SQL Server

 Oracle

 DB2

 MySQL
Database Concepts
2
A database is a collection of one or
more tables, each containing data
related to a particular topic
Terminology
 Database: a collection of interrelated tables
 Table: a logical grouping of related data
 A category of people, places, or things

 For example, employees or departments

 Organized into rows and columns

 Field: an individual piece of data pertaining to an


item, an employee name for instance
 Record: the complete data about a single item
such as all information about an employee
 A record is a row of a table
Database Table
 Each table has a primary key
 Uniquely identifies that row of the table

 Emp_Id is the primary key in this example

 Columns are also called fields or attributes


 Each column has a particular data type
Emp_Id First_Name Last_Name Department
001234 Ignacio Fleta Accounting
002000 Christian Martin Computer Support
Row 002122 Orville Gibson Human Resources
(Record) 003400 Ben Smith Accounting
003780 Allison Chong Computer Support

Column Field
VB and SQL Server Data Types
 VB data types must match table data types
 SQL Server and VB have similar data types

SQL Type Usage Visual Basic


Type
Bit True/false values Boolean
DateTime Dates and times Date,
DateTime
Decimal, Money Financial values Decimal
Float Real-number values Double
Int Integer values Integer
Smallint Integers -32,768 to 32,767 Short
Varchar(n) Variable length strings String
Text Strings more than 8000 char String
3 Introduction to ADO.NET
“Active Data Objects”(ADO)
 A set of class definitions included in the .NET
Framework that collaborate to provide .NET
applications (relatively) easy access to
databases.
 Designed for scalability.
 100’s or 1000’s of clients on a database server

 Offload functionality from server to client


The ADO.NET Object Model

Data
Handles
Provider
Adapter DataSet
D communicatio
Provides general
n with a The actual data
A disconnected access
physical data
to data C
T store. Knows how to do SQL
Connectio L
A n commands on the database
Command I
B
E
A
Reader N
S
T
E A light weight object for
sequential read-only access
to a query result.

ADO.N
ET
http://msdn.microsoft.com/en-us/library/a6cd7c08.aspx
Data Provider
 A data provider is used for connecting to a database,
executing commands and retrieving data, storing it in a
dataset, reading the retrieved data and updating the
database.
 Collection of Class Definitions
 Specific to a data source


MS SQL Server

Oracle

(others)

 Same set of classes for each data source

 Class name differs



SqlDataConnection vs OracleDataConnection

SqlCommand vs OracleCommand

etc.
DataSet
 DataSet is an in-memory representation of data.
 It is a disconnected, cached set of records that are
retrieved from a database.
 When a connection is established with the database, the
data adapter creates a dataset and stores data in it.
 After the data is retrieved and stored in a dataset, the
connection with the database is closed. This is called the
'disconnected architecture'. The dataset works as a virtual
database containing tables, rows, and columns.
The DataSet

From ADO.NET 2.0 Step by Step


DataGridView Control
4
The DataGridView Control Allows you to
Display a Database Table in a Grid Which
Can be Used at Runtime to Sort and Edit
the Contents of the Table
Connecting VB to a Database
 VB provides tools to display database tables
 Data binding links tables to controls on forms
 Controls called components establish the link

 A wizard guides you through the process

 We’ll use these data-related components:


 Data source – usually a database

 Binding source – connects data bound

controls to a dataset
 Table adapter – uses SQL to select data

 Dataset – in-memory copy of data from tables


Connecting VB to a Database
 The flow of data from database to application

 Data travels from data source to application


 Application can view/change dataset contents
 Changes to dataset can be written back to the
data source
Data-Bound Controls
5
Some Controls Can Be Bound to a Dataset.
A Data-bound Control Can be Used to
Display and Edit the Contents of a
Particular Row and Column
Advantages of Data-Binding
 Can bind fields in a data source to controls:
 Text boxes

 Labels

 Contents of data-bound controls change


automatically when moving from row to row
 Data-bound control also allow the contents of a
database field to be changed
Adding a New Data Source
 Open the Data Sources window
 Click the Add New Data Source
link

 Follow the steps in the


Data Source Configuration
Wizard to create a
connection to the database
Deleting a Data Source
 Once created, it’s almost impossible to rename a
data source
 Easier to delete and create a new data source
than rename one
 A data source named Employees for example
would be defined by a file named Employees.xsd
 To delete this data source:
 Select Employees.xsd file in Solution Explorer

 Press Delete
Binding Individual Fields to Controls
 Use the dataset in the Data Sources window
 Select Details from the table drop-down list

 Drag table to an open area of a form

 Creates a separate control for each field

 Can also drag columns individually

 Text and numeric fields added as text boxes


 Yes/No fields added as checkboxes
 DateTime fields use DateTimePicker controls
 Class demo…
6 Importance of Software Documentation:
 1. Clarify your business goals, requirements and activities: With a
proper documentation, you can share the business goals and requirement
with your managers and team mates so that they have a clear vision and
goals and the activity they perform will be more towards the success.
 2. Design and Specify your product: This comes in
Architectural/Design documents and it gives you complete overview of how
your products look like.
 3. Everything is clearly explained: When you makes End User
documentation of the product of software, you have to explain each and
everything about its working. It describes each feature of the program, and
assists the user in realizing these features.
 4. Any body can work on other's code: If you are a developer, it is
not sufficient to write good codes only but you also need to take cares about
the documentation part, which can be helpful to other developers while
working in a team.
 5. Helpful in proper communication: A good software
documentation is helpful in proper communication. The written procedure
helps you to make interaction within several departments.
Revision Questions:
 Describe the main advantages of documenting
your code/ application.

 Describe the following terms in relation to


connecting your VB application to a database.

ADO.Net object

Data source control

Dataset

Data Provider

Binding source

You might also like