Objectives
Designing Back End Database
Front End Design using ASP.NET
Writing Event Procedures
Front End-Back End Connectivity
Executing SQL Queries from Front End
Database
Collection of Data
Specific to a Topic
Efficient in Storage and Retrieval
Compactness
Physical Collection of Data on Storage
Media
DBMS
Data Base Management System
Collection of Programs
Functions:
Creation + Management of Database
Creation + Management of Database
Table Structure
Storage of Data
Manipulation of Data
RDBMS
Relational Data Base Management
System
Tabular DBMS
Data Storage in form of Tables
Table-Collection of:
Column: Vertical, Field, Property
Row: Horizontal, Record, Collection of
Field
Table
RollNo StName StDOB StEmail
2009-ag-2533 Ali Ahmad 25/12/1986 aliahmad@gmail.com
2010-ag-2686 Jawad Ahmad 23/05/1987 jawada@yahoo.com
2011-ag-1101 Shahid Nazir 05/06/1987 nazirsh@hotmail.com
2005-ag-4156 Junaid Ali 03/02/1982 j.ali@gmail.com
Fields/Column
Record/Row
Different RDBMS
Microsoft Access
Oracle
SQL Server
Back End
Database
Storage Purpose
Hidden from User
Database has a Name
Tables are Present in Database
Designing Back End
Designing Back End Involves:
Creating Database
Creating Tables
Specifying Columns/Fields
Each Have Its Unique Name
Tools:
SQL Server 2008 Compact Edition
SQL Server 2008 Management Studio
SQL Server Compact Edition
Integrated with Visual Studio 2010
Service Name: SQLEXPRESS
Database Extension: .sdf, .mdf
Suitable for PC Database Applications
.sdf: SQL Server Compact Database File
.mdf: SQL Server Database File
SQL Server 2008
Management Studio
Independent Installation
Default Service Name:
MSSQLSERVER
Database Extension: .mdf
Suitable for Client/Server Applications
.mdf: SQL Server Database File
1
Open Visual Studio 2010
Go to “Data Connections” in “Server
Explorer”
Right Click “Data Connections” and
Select “Add Connection”
“Add Connection” Dialog Box
2
3
4
Go to “Change” Portion of “Add
Connection” Dialog Box
“Change Data Source” Dialog Box
Select “Microsoft SQL Server
Database File” and Press “OK”
“Add Connection” Dialog Box Appears
Type in the Path and Database File
Name and Press “OK”
5
6
1
Go to “Data Connections” in “Server
Explorer” Area
Database.mdf will be present
Double Click Database
Right Click on “Table”
Click “Add New Table”
2
Write Down Table Specification as
Follows:
3
Set The Field “st_regno” as Primary
Key
Right Click on “st_regno” Field and
Select “Set Primary Key”
Press CTRL+S
Type Table Name “student_info” and
Press “OK”
Table will be Created
Front End
User Interface (GUI)
User`s Working Area
Used to Send Commands to DBMS
DBMS Executes Commands on
Database
Data Entry
Data Manipulation
Data/Information Retrieval
Front End Components
Web Forms
Controls
Text Boxes
Labels
Buttons
Check Boxes
Option Buttons etc
Menus
Web Form (1)
Main Content
Page Area
Place to Hold other Contents
Base of Application GUI
Single Web Site may Contain as many
Web Forms as Required
Form (2)
TextBox
Available in Toolbox
Used for Input
Can be:
Single Line
Multi Line
Masked (Password)
Label
Available in Toolbox
Used for Output
Button
Available in Toolbox
Used for Performing Operations
Command Button
Purpose:
Save
Clear
Exit
etc
Check Box
Available in Toolbox
Tick Box
Yes/No Purpose
Multiple Selection From A Group
Option Button
Available in Toolbox
Radio Button
Yes/No Purpose
Single Selection From A Group
Designing Front End
Selection of Controls Required
Placement on Form Control
Changing Properties
Customization of Controls:
Font
Resize
Coloring
Alignment
Common Properties
Name
Text
ForeColor
Font
Enabled
TabIndex
Designing Front End
Event
Happening of Anything
Different Controls have Different
Events
Single Left Click
Double Left Click
Mouse Move
Key Press
Procedure
Piece of Code
Performs Some Operation
Program can have Many Procedures
Procedure and Event Combination
Event Procedure
Writing Procedure for Events
Procedure Executes on the
Occurrence of Specific Event
Writing Event Procedures
Current Scenario:
Save Data Button – Click
Database Connectivity and Query to Save
Data in Database (INSERT Query)
Clear Form Button – Click
Clear Form
Exit Button – Click
Exiting the Application
Connectivity
Importing Namespace
Using SqlConnection Class
ConnectionString
Opening Connection
Checking Connection State
Closing Connections
Namespace
Used to Create Hierarchy
Contain:
Classes
Structures
etc
Importing Namespaces
Importing Namespaces in General
Declaration Section using Keyword
‘Imports’:
System.Data
System.Data.Sql
System.Data.SqlClient
SqlConnection Class
Represents Unique Connection to
Database
Used to Open Connection with
Database
Must be Declared and Initialized
Object Instance Creation
Contain Properties and Methods
Important Members
ConnectionString
State
Open()
Close()
ConnectionString
Important Property
Property Name: ConnectionString
Must be Set Properly to Open
Connection
String Type
String Required to Open A Connection
to SQL Server Database
ConnectionString Parts
Data Source:
Server Name or Service Name
e.g. SQLEXPRESS
AttachDbFilename:
Complete Path of Database File
Integrated Security:
Security Password
TRUE or FALSE
Connect Timeout:
Time to Cancel Query in case of Error
Opening Connection
Open() Method of SqlConnection
Class
Used to Open a Connection to
Database
Connection Must be Open Before
Manipulating Database
Checking Connection State
State Property of SqlConnection
Class
Boolean Property (TRUE or FALSE)
Used to Check Status of Connection
Outcomes:
TRUE (Opened Connection)
FALSE (Closed Connection)
Closing Connection
Close() Method of SqlConnection
Class
Closes Connection to Database
Connection Must be Closed and
Reopened After Performing Database
Manipulation
SQL Queries
SQL—Structured Query Language
Query—Any Question
Executed on Database by DBMS
Sent By API (Application Program
Interface)
SQL Queries
API (Application Program Interface)
DBMS
User(s)
Database
SQL Query Types
DDL:
Database Creation
Table Structure Management
DML:
INSERT (Entering New Data)
UPDATE (Update Existing Data)
DELETE (Deleting Existing Data)
SELECT (Retrieving Data)
Query Execution
Importing Namespace
Using SqlCommand Class
Initializing Command Text and
Registering Connection
Executing INSERT Query
Using SqlDataReader, SqlDataAdapter
Classes
Retrieving and Showing Data
Importing Namespaces
Importing Namespaces in General
Declaration Section using Keyword
‘Imports’:
System.Data
System.Data.Sql
System.Data.SqlClient
SqlCommand Class
Deals with Database
Executes SQL Commands
Specification of SqlConnection
Must be Declared and Initialized
Collection of Properties and Methods
Important Members
SqlCommand(String,Connection) –
Constructor
CommandText
Connection
ExecuteReader()
ExecuteNonQuery()
Cancel()
SqlCommand(String,Connection)
Constructor
SqlCommand(String,Connection)
Instantiates SqlCommand Object with
String CommandText and Connection
SqlConnection
CommandText
Property
Gets or Sets
SQL Command to be Executed by
SqlCommand through SqlConnection
Command can be:
INSERT
UPDATE
DELETE
SELECT
String Type
Connection
Property
Gets or Sets
SQL Connection to Execute SQL
Command
Command can be:
INSERT
UPDATE
DELETE
SELECT
SqlConnection Type
ExecuteReader()
Method
Execute Commands Returning Rows
i.e. SELECT Query
Executes SELECT SqlCommand
Return Rows and Store them in
SqlDataReader Object
ExecuteNonQuery()
Method
Executes Commands Not Retrieving
Rows i.e. INSERT, UPDATE, DELETE
Executes INSERT/UPDATE/DELETE
SqlCommand
Doesn`t Return Anything
Cancel()
Method
Tries to Cancel Execution of SQL
Command Specified by SqlCommand
Object
Recipe….
Open and Test Connection Using
SqlConnection Object
SqlCommand Object Creation
Set CommandText and Connection
Properties
Execute Method ExecuteNonQuery()
Display Message Accordingly
Recipe….
Open and Test Connection Using
SqlConnection Object
SqlCommand Object Creation
Set CommandText and Connection
Properties
Execute Method ExecuteReader() and
Store Data in SqlDataReader Object
Display Data
SqlDataReader Class
Reads Data Rows Directly from SQL
Server Database
Reading Order—Forward
Loops – To Read Multiple Rows
Efficient
Contains Properties and Methods
Must be Open to Read Data
Important Members
FieldCount
HasRows
IsClosed
Close()
FieldCount
Property
Gets Number of Columns in Returned
Row
Type: Integer
HasRows
Property
Boolean Values
Indicates Whether Rows are Returned
in Response to a SELECT Query
Outcomes:
TRUE – Rows Returned
FALSE – No Row Returned
IsClosed
Property
Boolean Values
Indicates Whether SqlDataReader is
Closed or Not
Outcomes:
TRUE – Closed
FALSE -- Open
Close()
Method
Closes SqlDataReader Object
SqlDataReader Object Must be
Closed to Execute Another SQL
Command and to Return Data in the
Same Reader
Thank You

Web based database application design using vb.net and sql server