Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 71

VB.

Net Seminar
JONI NEIL B. CAPUCAO
Master of Information Technology
Institute of Information Technology
College of Arts and Sciences
Partido State University
February 27-28, 2016

Part I (Morning Session)


Lesson

1. Introduction

Microsoft .NET
Visual Studio 2012
Visual Studio Integrated Development Environment
Creating and Saving Projects
Activity 1

Lesson

2. Building Interfaces

Customizing Forms
Adding Controls to the
Activity 2

Lesson

Form

3. Writing the Code

Understanding Procedures
Handling Errors
Activity 3

and Functions

Part II (Afternoon Session)

Lesson 4. Working with Oracle Database

Lesson 5. Creating Connection to Oracle Database

Creating and Managing users


Oracle Data Provider for .Net
Activity 4
adding project references to support Oracle class libraries in
your .NET project
Creating Oracle Database connection strings
Working with Connection, Command, and DataReader/Datasets
objects
Activity 5

Hands on Exercises

Developing C.R.U.D. Modules


Working with Report Viewer

Lesson 1.
Introduction

What is Microsoft .NET?

.NET represents an advanced new generation of software


that will drive the Next Generation Internet. Its purpose
is to make information available any time, any place, and
on any device.
Quick Definition

.NET is an initiative to integrate all Microsoft products with the


Next Generation web.

http://www.microsoft.com/net/

What is Microsoft .NET? (Cont.)


Core

components of .NET are:

.NET

Infrastructure and Tools

.NET Enterprise Servers

SQL 2000

Exchange 2000

ISA 2000

Host Integration Server 2000

Application Center 2000

BizTalk Server 2000

Commerce Server 2000

.NET Framework

Visual Studio.NET

Windows.NET

Core components of .NET: (cont)


.NET

Services

An

integrated set of building block services for the new


Internet, including Passport.NET (for user authentication), and
services for file storage, user preference management,
calendar management, and many others.

.NET

A broader, more adaptive user experience, where information is


delivered in a variety of ways on a variety of different devices.

.NET

User Experience
Device Software

Enables a new breed of smart Internet devices that can leverage Web
Services

http://www.microsoft.com/business/vision/netvision.asp

.NET Framework

is a software framework developed by Microsoft that runs


primarily on Microsoft Windows.

provides language interoperability (each language can use


code written in other languages) across several
programming languages. (CLR)

It includes a large class library known as Framework Class


Library (FCL) and

Programs written for .NET Framework execute in


a software environment known as

Common Language Runtime (CLR), an application virtual


machine that provides services such as security, memory
management, and exception handling.

FCL and CLR together constitute .NET Framework.

The .NET Framework

Common Language Runtime (CLR)

A common runtime for all .NET languages

Common type system

Common metadata

Intermediate Language (IL) to native code compilers

Memory allocation and garbage collection

Code execution and security

Over 15 languages supported today

C#, VB, Jscript, Visual C++ from Microsoft

Perl, Python, Smalltalk, Cobol, Haskell, Mercury, Eiffel, Oberon,


Oz, Pascal, APL, CAML, Scheme, etc.

Common Language Runtime (CLR)- cont

Enables cross-language interoperability

Language/Hardware/OS Independent

Common Language Specification describes interoperability


requirements
Compact framework for small devices

Industrial strength Garbage collector

Designed for multi-processor servers

CLR: Execution Model


Source
code
Managed
code

VB

C#

C++

Compiler

Compiler

Compiler

Assembly
IL Code

Assembly
IL Code

Assembly
IL Code

Common Language Runtime


JIT Compiler
Native Code

Operating System Services

Unmanaged
Component

.NET Framework Libraries

Single consistent set of object oriented class libraries to


enable building distributed web applications (Unified
Classes)

Built using classes arranged across logical hierarchical


namespaces

For example: System.Data.SQL

Work with all CLR languages

No more VBRun or MFC divide

.NET Framework Libraries


Unified Classes
Web Classes (ASP.NET)
Controls, Caching, Security, Session, Configuration etc

Data (ADO.NET)

Windows Forms

ADO, SQL,Types etc

Design, Cmpnt Model etc

XML Classes

Drawing Classes

XSLT, Path, Serialization etc Drawing, Imaging, Text, etc

System Classes
Collections, Diagnostics, Globalization, IO, Security,
Threading Serialization, Reflection, Messaging etc

Visual Studio.NET
Integrated
Visual

Development Environment

Basic.NET

Inheritance,

Visual

Overloading, Free Threading

C++

Integration

(classes)

with .NET Framework with managed extensions

C#
New

development language

Based

on C/C++ with Garbage Collection/Memory Management

http://msdn.microsoft.com/vstudio

VS.NET Features
Single

IDE for all


Languages
Server Explorer

Event Viewer, Message Queues,


Services

SQL Databases, Data


Connection, Etc.

Integrated

IE Browser
HTML/XML Editors

Macros/Macro

Explorer
Solution Explorer
Tabbed Documents
Dynamic Help
Common Forms Editor
VB.NET, C++,

and C#

Visual Basic.NET

What is Visual Basic?

Visual Basic(VB) is a programming environment from Microsoft in


which a programmer uses a graphical user interface (GUI) to choose
and modify preselected sections of code written in theBASIC
programming language

"Visual" refers to the method used to create what the user seesthegraphical
user interface, or GUI.

"Basic" refers to the BASIC (Beginners All-Purpose Symbolic Instruction Code)


programming language. The code looks a lot like English Language. You can
create useful programs by learning just a few of its features.

Starting Visual Studio 2012

On the Windows Start screen, click Visual Studio 2012.

You may also use the search windows to locate Visual Studio 2012.

If you are prompted to identify your programming preferences,


select Visual Basic Development Settings

After starting Visual Studio, youre ready to explore the


Visual Studio IDE.

Integrated Development Environment

To start a new Visual Basic 2012


project, simply click on New
Project.. to launch the Visual Basic
New Project page.

Creating New Project in Visual Basic 2012

In the Visual Basic New


Project page

Select Windows Form


Application

Change the default Name


(WindowsApplication1) to
the desired Project Name

Click Ok button to
proceed to the Project
Page.

Visual Basic 2012 Project Page

Project Page comprises


a few windows,

the Form window,

the Solution Explorer


window, and

the Properties
window

the toolboxwhich
contains many useful
controls that allows a
programmer
todevelophis or her
VB programs.

Switch Themes in Visual Studio

Open the Options dialog (Tools -> Options). Under Environment -> General, the first
setting is "Color theme." You can use this to switch between Light and Dark.

Saving
Project

Click File Menu then Click Save All or press CrtlShift-S.

Save Project Dialog Box appears.

Provide a project Name, location of the Project and the


Solution Name.

Make sure Create directory for solution is checked.

Activity 1

Activity 1 Creating and Saving VB Project

Step 1. Open Visual Studio 2012

Step 2. Save your projects using Student Record as the Filename.

Step 3. Close your Student Record Project

Lesson 2. Building Interfaces


Customizing
Designer
Code

Forms

Window

Window

DEMO
MDI

Form, Forms

Object Naming Convention


Control type

prefix

Example

Database

db

dbAccounts

Check box

chk

chkReadOnly

Combo box, drop-down list box

cbo

cboEnglish

Command button

cmd

cmdExit

Common dialog

dlg

dlgFileOpen

Date picker

dtp

dtpPublished

Form

frm

frmEntry

Frame

fra

fraLanguage

Image

img

imgIcon

Label

lbl

lblHelpMessage

Object Naming Convention (cont..)


Control type

prefix

Example

List box

lst

lstPolicyCodes

ListView

lvw

lvwHeadings

Menu

mnu

mnuFileOpen

Option button

opt

optGender

Picture box

pic

picVGA

ProgressBar

prg

prgLoadFile

StatusBar

sta

staDateTime

User

usr

usrNew

Text box

txt

txtLastName

Timer

tmr

tmrAlarm

Activity 2

Activity 2

Create an MDI Form

Name - frmMain

Window State - Maximized

Text Student Information

Name

mnuMain

File
Exit

Add a Menu Bar

(mnuExit)

Enroll Students (mnuEroll)

Add a Status Bar

Name - staMain

Date - staDate

Adding Controls to the Form


Walkthrough in adding and customizing:
Label
TextBox
ComboBox
Buttons
ListView
GroupBox

ACTIVITY 3

Lesson 3. Writing the Code

Understanding

Functions

Functions

are named blocks of program code that perform a specific


task and return a result.

Public Function Sum(ByRef Number1 As Double, ByRef Number2 As Double) As Double


'Return the result by writing it to a variable having the same name as the function
Sum = Number1 + Number2
End Function

Procedures or Subroutine

A subroutine is like a function, just that it does not


return a result.

Public Sub Tell(ByVal MyString1 as String, ByVal MyString2 as String)


MsgBox MyString1 & MyString2
End Sub

Handling Errors
Only

perfect programmers create perfect


code from the beginning.

The

rest must address imperfections along


the way to developing a successful
application.

Definitions of Errors and Exceptions

The terms, error and exception, are often used


interchangeably

In fact, an error, which is an event that happens during


the execution of code, interrupts or disrupts the code's
normal flow and creates an exception object

When an error interrupts the flow, the program tries to


find an exception handler a block of code that tells it
how to react that will help it resume the flow

In other words, an error is the event; an exception is the


object that the event creates.

Structured versus Unstructured


Structured

exception handling is simply that


using a control structure containing exceptions,
isolated blocks of code, and filters to create an
exception handling mechanism. This allows your
code to differentiate between different types of
errors and react in accordance with
circumstances.

In

unstructured exception handling, an On Error


statement at the beginning of the code handles
all exceptions.

Structured versus Unstructured (cont)


Structured

exception handling is significantly


more versatile, robust, and flexible than
unstructured.

If

possible, use structured exception handling.

However, you

might use unstructured exception


handling under some circumstances

The Try...Catch...Finally block

The Try statement provides the code that is being tested


for exceptions.

Catch clauses identify blocks of code that are associated


with specific exceptions.

The Finally statement contains code that executes


regardless of whether or not an exception occurs within
the Try block. A Finally statement will execute even after
an Exit Try or Exit Sub. This code often performs clean-up
tasks, such as closing files or clearing buffers.

Structured Exception Handling


Try
varAvailableSeats = varAuditoriumSeats - varNumberOfGuests
Catch ex As Exception When varAuditoriumSeats = 0
MsgBox("Auditorium lacks chairs!")
Exit Sub
Catch ex As Exception When varAvailableSeats < 0
MsgBox("There are no more available seats.")
Exit Sub
Finally
MsgBox("Thank you for your interest in our concert.")
End Try

Unstructured Exception Handling

Unstructured exception handling is implemented using theErrobject


and three statements:On Error, Resume, andError.

TheOn Errorstatement establishes a single exception handler that catches


all thrown exceptions

Resume and Resume Next

TheResumestatement by itself can return control to the statement that caused


the exception.

Resume Nextcan be used to allow graceful failures;

The Error Object

The values of the properties of theErrobject are determined by the error that just
occurred

Sample of Unstructured Exception Handling


On Error GoTo

Private Sub FlawlessCode()


On Error GoTo Whoops
' Code doing various things
' Don't keep going into the error handling code.
Return
Whoops:
' Provide user with error information.
MsgBox ("Unexpected Error:" & Err.Description)
Return
End Sub

Sample of Unstructured Exception Handling (cont)


On Error Resume Next
Dim ErrorMessage As String
' Construct an error message if an error occurs.
On Error Resume Next
Err.Raise (13) ' Generate type mismatch error.
' Check to see if an error has occurred. If so, show message.
If Err.Number <> 0 Then
ErrorMessage = "Error # " & Str(Err.Number) & " was generated by "
_
& Err.Source & vbCrLf & Err.Description
' Display the message as a critical message.
MsgBox(ErrorMessage, MsgBoxStyle.Critical, "Error")
End If

Activity 3

PART II

Lesson 4. Working with Oracle Database


Creating

User Accounts and Managing Privileges

Walkthrough

in creating user account using Oracle


Database Express Home Page.

Oracle Data Provider for .Net


Oracle

Data Provider for .NET (ODP.NET) features


optimized ADO.NET data access to the Oracle database.
ODP.NET

allows developers to take advantage of advanced


Oracle database functionality, including Real Application
Clusters, XML DB, and self-updating client caches.

ODP.NET

makes using Oracle from .NET more flexible, faster,


and more stable. ODP.NET includes many features not found in
other .NET drivers, including flexible LOB data types, selftuning, run-time connection load balancing, fast connection
failover, and Advanced Queuing.

Activity 4

Lesson 5
Creating
adding

Connection to Oracle Database

project references to support Oracle


class libraries in your .NET project
Creating Oracle Database connection strings
Working with Connection, Command, and
DataReader/Datasets objects
Activity 5

Bound vs Unbound controls - Which should I use?

When developers use bound controls they end up putting a lot of


business logic into the click events, change events and so on, so when
rules change it is difficult to ferret out all the places in the code that
need to be touched. As long as the application is coded to take these
things into consideration then bound controls are just another tool in
the toolbox.

I guess the issue is that it is often the developers who haven't yet
learned to pay attention to these things who are the ones that bound
controls are most attractive to, so the code produced ends up being
less than ideal.

Bound vs Unbound controls - Which should I use?

Typically, when developers use bound controls they end up putting a


lot of business logic into the click events, change events and so on, so
when rules change it is difficult to ferret out all the places in the
code that need to be touched. As long as the application is coded to
take these things into consideration then bound controls are just
another tool in the toolbox.

I guess the issue is that it is often the developers who haven't yet
learned to pay attention to these things who are the ones that bound
controls are most attractive to, so the code produced ends up being
less than ideal.

Should you use ADO.NET DataReader or DataSet?


In the beginning, there was the recordset, a central
feature of classic ADO. Like a Swiss army knife, it wasnt the
perfect tool for every job, but given the correct
configuration, it could do whatever you needed it to do.
However, ADO.NET was a totally new set of components,
and it was optimized for the Internet world.
When accessing data with ADO.NET, you can use either a
DataReader or a DataSet

Access through DataReader

So, what is a DataReader? It is a one-way, forward-only


method of reading data. A common use of the DataReader
to read through a result set.

When you get the results into the DataReader, its


important to note that the "cursor" or logical pointer into
the returned data is just before the first row. You need to
call .Read() once to read any data. .Read() will return true
as long as there is an additional row to be read.

Access through DataSet

A DataSet is a database-independent, in-memory data


store that enables the developer to directly access all
rows and columns of one or many tables that a DataSet
can contain.

The DataSet has a Tables collection of DataTable objects,


and the DataTable has a Rows collection that can be
indexed to get to a particular row by number. The Rows
collection has a .Count property that enables the
developer to determine the number of rows in any of the
tables in a DataSet.

Access through DataSet

The DataSet enables you to update the in-memory copy of


the data, and use a DataAdapter specific to a data
provider to have those changes persisted back in the
database.

The important thing to remember is that the DataSet is


independent of any particular database; the only
connection that exists is when the DataSet is used in
conjunction with a DataAdapter.

Which to use?

If you need read-only access to the data, something often


done inside an ASP.NET application, using a DataReader
makes sense. Unless you are going to persist the data
between postbacks, the data that you use to, say,
populate a grid, will not be present when someone clicks
on one of the rows of that grid.

When updates to the data are required, you can either


directly execute UPDATE, INSERT or DELETE SQL
statements, or you can call a stored procedure. While this
seems like more work that just updating data in a
DataSet, it gives you more control over exactly how the
updates take place, and works very well in a web
environment.

Which to use?

One possible disadvantage of using a DataReader is that


the connection must be open while you are accessing the
data. If you will be doing lengthy processing with each row
of returned data, a DataSet might be a better idea.

If you are building a Windows Forms application (or a


"Smart Client"), DataSets offer some advantages. Since the
application will maintain its state over the entire time it is
running, and client context does not tie up server
resources, using a DataSet can be very convenient for
Windows Forms applications.

Which to use?

The dark side of using DataSets is that the data remains in


memory for as long as you use it. If you are retrieving
thousands or millions of rows, a DataSet is probably not an
ideal solution

Activity 5

HANDS ON EXERCISES

Thank You !!!

You might also like