77
Web Based Database Application Development Using 1. ASP.NET with VB.NET 2. SQL Server

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

Embed Size (px)

Citation preview

Web BasedDatabase Application DevelopmentUsing1. ASP.NET with VB.NET2. SQL Server

Objectives

Designing Back End DatabaseFront End Design using ASP.NETWriting Event ProceduresFront End-Back End ConnectivityExecuting SQL Queries from Front End

Database

Collection of DataSpecific to a TopicEfficient in Storage and RetrievalCompactnessPhysical Collection of Data on Storage

Media

DBMS

Data Base Management SystemCollection of ProgramsFunctions:

Creation + Management of DatabaseCreation + Management of Database

Table StructureStorage of DataManipulation of Data

RDBMS

Relational Data Base Management System

Tabular DBMSData Storage in form of TablesTable-Collection of:

Column: Vertical, Field, PropertyRow: Horizontal, Record, Collection of

Field

Table

RollNo StName StDOB StEmail

2009-ag-2533 Ali Ahmad 25/12/1986 [email protected]

2010-ag-2686 Jawad Ahmad 23/05/1987 [email protected]

2011-ag-1101 Shahid Nazir 05/06/1987 [email protected]

2005-ag-4156 Junaid Ali 03/02/1982 [email protected]

Fields/Column

Record/Row

Different RDBMS

Microsoft AccessOracleSQL Server

DESIGNIN

G BACK E

ND

Back End

DatabaseStorage PurposeHidden from UserDatabase has a NameTables are Present in Database

Designing Back End

Designing Back End Involves:Creating DatabaseCreating TablesSpecifying Columns/FieldsEach Have Its Unique NameTools:

SQL Server 2008 Compact EditionSQL Server 2008 Management Studio

SQL Server Compact Edition

Integrated with Visual Studio 2010Service Name: SQLEXPRESSDatabase Extension: .sdf, .mdfSuitable for PC Database Applications

.sdf: SQL Server Compact Database File.mdf: SQL Server Database File

SQL Server 2008 Management StudioIndependent InstallationDefault Service Name:

MSSQLSERVERDatabase Extension: .mdfSuitable for Client/Server Applications

.mdf: SQL Server Database File

DATABASE C

REATION

1

Open Visual Studio 2010Go 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 BoxSelect “Microsoft SQL Server

Database File” and Press “OK”“Add Connection” Dialog Box AppearsType in the Path and Database File

Name and Press “OK”

5

6

TABLE C

REATION

1

Go to “Data Connections” in “Server Explorer” Area

Database.mdf will be presentDouble Click DatabaseRight Click on “Table”Click “Add New Table”

2

Write Down Table Specification as Follows:

3Set The Field “st_regno” as Primary

KeyRight Click on “st_regno” Field and

Select “Set Primary Key”Press CTRL+SType Table Name “student_info” and

Press “OK”Table will be Created

DESIGNIN

G FRONT E

ND

Front End

User Interface (GUI)User`s Working AreaUsed to Send Commands to DBMSDBMS Executes Commands on

DatabaseData EntryData ManipulationData/Information Retrieval

Front End Components

Web FormsControls

Text BoxesLabelsButtonsCheck BoxesOption Buttons etc

Menus

Web Form (1)

Main ContentPage AreaPlace to Hold other ContentsBase of Application GUISingle Web Site may Contain as many

Web Forms as Required

Form (2)

TextBox

Available in ToolboxUsed for InputCan be:

Single LineMulti LineMasked (Password)

Label

Available in ToolboxUsed for Output

Button

Available in ToolboxUsed for Performing OperationsCommand ButtonPurpose:

SaveClearExitetc

Check Box

Available in ToolboxTick BoxYes/No PurposeMultiple Selection From A Group

Option Button

Available in ToolboxRadio ButtonYes/No PurposeSingle Selection From A Group

Designing Front End

Selection of Controls RequiredPlacement on Form ControlChanging PropertiesCustomization of Controls:

FontResizeColoringAlignment

Common Properties

NameTextForeColorFontEnabledTabIndex

Designing Front End

WRIT

ING E

VENT PROCEDURES

Event

Happening of AnythingDifferent Controls have Different

EventsSingle Left ClickDouble Left ClickMouse MoveKey Press

Procedure

Piece of CodePerforms Some OperationProgram can have Many ProceduresProcedure and Event Combination

Event Procedure

Writing Procedure for EventsProcedure 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 – ClickClear Form

Exit Button – ClickExiting the Application

FRONT END-B

ACK END C

ONNECTIVIT

Y

Connectivity

Importing NamespaceUsing SqlConnection ClassConnectionStringOpening ConnectionChecking Connection StateClosing Connections

Namespace

Used to Create HierarchyContain:

ClassesStructuresetc

Importing Namespaces

Importing Namespaces in General Declaration Section using Keyword ‘Imports’:System.DataSystem.Data.SqlSystem.Data.SqlClient

SqlConnection Class

Represents Unique Connection to Database

Used to Open Connection with Database

Must be Declared and InitializedObject Instance CreationContain Properties and Methods

Important Members

ConnectionStringStateOpen()Close()

ConnectionString

Important PropertyProperty Name: ConnectionStringMust be Set Properly to Open

ConnectionString TypeString Required to Open A Connection

to SQL Server Database

ConnectionString Parts

Data Source:Server Name or Service Namee.g. SQLEXPRESS

AttachDbFilename:Complete Path of Database File

Integrated Security:Security PasswordTRUE 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 ConnectionOutcomes:

TRUE (Opened Connection)FALSE (Closed Connection)

Closing Connection

Close() Method of SqlConnection Class

Closes Connection to DatabaseConnection Must be Closed and

Reopened After Performing Database Manipulation

EXECUTING S

QL QUERIE

S

SQL Queries

SQL—Structured Query LanguageQuery—Any QuestionExecuted on Database by DBMSSent By API (Application Program

Interface)

SQL Queries

API (Application Program Interface)

DBMS

User(s)

Database

SQL Query Types

DDL:Database CreationTable Structure Management

DML:INSERT (Entering New Data)UPDATE (Update Existing Data)DELETE (Deleting Existing Data)SELECT (Retrieving Data)

Query Execution

Importing NamespaceUsing SqlCommand ClassInitializing Command Text and

Registering ConnectionExecuting INSERT QueryUsing SqlDataReader, SqlDataAdapter

ClassesRetrieving and Showing Data

Importing Namespaces

Importing Namespaces in General Declaration Section using Keyword ‘Imports’:System.DataSystem.Data.SqlSystem.Data.SqlClient

SqlCommand Class

Deals with DatabaseExecutes SQL CommandsSpecification of SqlConnectionMust be Declared and InitializedCollection of Properties and Methods

Important Members

SqlCommand(String,Connection) – Constructor

CommandTextConnectionExecuteReader()ExecuteNonQuery()Cancel()

SqlCommand(String,Connection)

ConstructorSqlCommand(String,Connection)Instantiates SqlCommand Object with

String CommandText and Connection SqlConnection

CommandText

PropertyGets or Sets

SQL Command to be Executed by SqlCommand through SqlConnection

Command can be:INSERTUPDATEDELETESELECT

String Type

Connection

PropertyGets or Sets

SQL Connection to Execute SQL Command

Command can be:INSERTUPDATEDELETESELECT

SqlConnection Type

ExecuteReader()

MethodExecute Commands Returning Rows

i.e. SELECT QueryExecutes SELECT SqlCommandReturn Rows and Store them in

SqlDataReader Object

ExecuteNonQuery()

MethodExecutes Commands Not Retrieving

Rows i.e. INSERT, UPDATE, DELETEExecutes INSERT/UPDATE/DELETE

SqlCommandDoesn`t Return Anything

Cancel()

MethodTries to Cancel Execution of SQL

Command Specified by SqlCommand Object

EXECUTING IN

SERT,UPDATE,D

ELETE

Recipe….

Open and Test Connection Using SqlConnection Object

SqlCommand Object CreationSet CommandText and Connection

PropertiesExecute Method ExecuteNonQuery()Display Message Accordingly

EXECUTING S

ELECT

Recipe….

Open and Test Connection Using SqlConnection Object

SqlCommand Object CreationSet CommandText and Connection

PropertiesExecute Method ExecuteReader() and

Store Data in SqlDataReader ObjectDisplay Data

SqlDataReader Class

Reads Data Rows Directly from SQL Server Database

Reading Order—ForwardLoops – To Read Multiple RowsEfficientContains Properties and MethodsMust be Open to Read Data

Important Members

FieldCountHasRowsIsClosedClose()

FieldCount

PropertyGets Number of Columns in Returned

RowType: Integer

HasRows

PropertyBoolean ValuesIndicates Whether Rows are Returned

in Response to a SELECT QueryOutcomes:

TRUE – Rows ReturnedFALSE – No Row Returned

IsClosed

PropertyBoolean ValuesIndicates Whether SqlDataReader is

Closed or NotOutcomes:

TRUE – ClosedFALSE -- Open

Close()

MethodCloses SqlDataReader ObjectSqlDataReader Object Must be

Closed to Execute Another SQL Command and to Return Data in the Same Reader

Thank You