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

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

Aug 11, 2015

Download

Technology

Ammara Arooj
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Web based database application design using vb.net and sql server

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

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

Objectives

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

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

Database

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

Media

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

DBMS

Data Base Management SystemCollection of ProgramsFunctions:

Creation + Management of DatabaseCreation + Management of Database

Table StructureStorage of DataManipulation of Data

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

RDBMS

Relational Data Base Management System

Tabular DBMSData Storage in form of TablesTable-Collection of:

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

Field

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

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

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

Different RDBMS

Microsoft AccessOracleSQL Server

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

DESIGNIN

G BACK E

ND

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

Back End

DatabaseStorage PurposeHidden from UserDatabase has a NameTables are Present in Database

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

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

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

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

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

SQL Server 2008 Management StudioIndependent InstallationDefault Service Name:

MSSQLSERVERDatabase Extension: .mdfSuitable for Client/Server Applications

.mdf: SQL Server Database File

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

DATABASE C

REATION

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

1

Open Visual Studio 2010Go to “Data Connections” in “Server

Explorer”Right Click “Data Connections” and

Select “Add Connection”“Add Connection” Dialog Box

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

2

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

3

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

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”

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

5

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

6

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

TABLE C

REATION

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

1

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

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

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

2

Write Down Table Specification as Follows:

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

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

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

DESIGNIN

G FRONT E

ND

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

Front End

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

DatabaseData EntryData ManipulationData/Information Retrieval

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

Front End Components

Web FormsControls

Text BoxesLabelsButtonsCheck BoxesOption Buttons etc

Menus

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

Web Form (1)

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

Web Forms as Required

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

Form (2)

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

TextBox

Available in ToolboxUsed for InputCan be:

Single LineMulti LineMasked (Password)

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

Label

Available in ToolboxUsed for Output

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

Button

Available in ToolboxUsed for Performing OperationsCommand ButtonPurpose:

SaveClearExitetc

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

Check Box

Available in ToolboxTick BoxYes/No PurposeMultiple Selection From A Group

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

Option Button

Available in ToolboxRadio ButtonYes/No PurposeSingle Selection From A Group

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

Designing Front End

Selection of Controls RequiredPlacement on Form ControlChanging PropertiesCustomization of Controls:

FontResizeColoringAlignment

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

Common Properties

NameTextForeColorFontEnabledTabIndex

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

Designing Front End

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

WRIT

ING E

VENT PROCEDURES

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

Event

Happening of AnythingDifferent Controls have Different

EventsSingle Left ClickDouble Left ClickMouse MoveKey Press

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

Procedure

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

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

Event Procedure

Writing Procedure for EventsProcedure Executes on the

Occurrence of Specific Event

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

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

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

FRONT END-B

ACK END C

ONNECTIVIT

Y

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

Connectivity

Importing NamespaceUsing SqlConnection ClassConnectionStringOpening ConnectionChecking Connection StateClosing Connections

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

Namespace

Used to Create HierarchyContain:

ClassesStructuresetc

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

Importing Namespaces

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

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

SqlConnection Class

Represents Unique Connection to Database

Used to Open Connection with Database

Must be Declared and InitializedObject Instance CreationContain Properties and Methods

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

Important Members

ConnectionStringStateOpen()Close()

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

ConnectionString

Important PropertyProperty Name: ConnectionStringMust be Set Properly to Open

ConnectionString TypeString Required to Open A Connection

to SQL Server Database

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

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

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

Opening Connection

Open() Method of SqlConnection Class

Used to Open a Connection to Database

Connection Must be Open Before Manipulating Database

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

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)

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

Closing Connection

Close() Method of SqlConnection Class

Closes Connection to DatabaseConnection Must be Closed and

Reopened After Performing Database Manipulation

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

EXECUTING S

QL QUERIE

S

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

SQL Queries

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

Interface)

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

SQL Queries

API (Application Program Interface)

DBMS

User(s)

Database

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

SQL Query Types

DDL:Database CreationTable Structure Management

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

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

Query Execution

Importing NamespaceUsing SqlCommand ClassInitializing Command Text and

Registering ConnectionExecuting INSERT QueryUsing SqlDataReader, SqlDataAdapter

ClassesRetrieving and Showing Data

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

Importing Namespaces

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

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

SqlCommand Class

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

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

Important Members

SqlCommand(String,Connection) – Constructor

CommandTextConnectionExecuteReader()ExecuteNonQuery()Cancel()

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

SqlCommand(String,Connection)

ConstructorSqlCommand(String,Connection)Instantiates SqlCommand Object with

String CommandText and Connection SqlConnection

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

CommandText

PropertyGets or Sets

SQL Command to be Executed by SqlCommand through SqlConnection

Command can be:INSERTUPDATEDELETESELECT

String Type

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

Connection

PropertyGets or Sets

SQL Connection to Execute SQL Command

Command can be:INSERTUPDATEDELETESELECT

SqlConnection Type

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

ExecuteReader()

MethodExecute Commands Returning Rows

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

SqlDataReader Object

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

ExecuteNonQuery()

MethodExecutes Commands Not Retrieving

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

SqlCommandDoesn`t Return Anything

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

Cancel()

MethodTries to Cancel Execution of SQL

Command Specified by SqlCommand Object

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

EXECUTING IN

SERT,UPDATE,D

ELETE

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

Recipe….

Open and Test Connection Using SqlConnection Object

SqlCommand Object CreationSet CommandText and Connection

PropertiesExecute Method ExecuteNonQuery()Display Message Accordingly

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

EXECUTING S

ELECT

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

Recipe….

Open and Test Connection Using SqlConnection Object

SqlCommand Object CreationSet CommandText and Connection

PropertiesExecute Method ExecuteReader() and

Store Data in SqlDataReader ObjectDisplay Data

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

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

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

Important Members

FieldCountHasRowsIsClosedClose()

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

FieldCount

PropertyGets Number of Columns in Returned

RowType: Integer

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

HasRows

PropertyBoolean ValuesIndicates Whether Rows are Returned

in Response to a SELECT QueryOutcomes:

TRUE – Rows ReturnedFALSE – No Row Returned

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

IsClosed

PropertyBoolean ValuesIndicates Whether SqlDataReader is

Closed or NotOutcomes:

TRUE – ClosedFALSE -- Open

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

Close()

MethodCloses SqlDataReader ObjectSqlDataReader Object Must be

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

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

Thank You