85
Visual Basic .Net Visual Basic .Net Seminar June 7, 2004 Seminar June 7, 2004

Visual Basic.Net Seminar June 7, 2004. Topics Today include The.Net Framework Studio.Net Environment VB.Net Introduction to VB.Net Loops and

Embed Size (px)

Citation preview

Page 1: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Visual Basic .NetVisual Basic .Net

Seminar June 7, 2004Seminar June 7, 2004

Page 2: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Topics Today includeTopics Today include

The .Net FrameworkThe .Net Framework Studio .Net EnvironmentStudio .Net Environment VB .NetVB .Net Introduction to VB .NetIntroduction to VB .Net Loops and Control StructuresLoops and Control Structures

Page 3: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The .Net FrameworkThe .Net Framework

What is the .Net FrameworkWhat is the .Net Framework Common Language RuntimeCommon Language Runtime .Net Managed Assemblies.Net Managed Assemblies Compilation of .Net CodeCompilation of .Net Code .Net Framework Class Library.Net Framework Class Library .Net Languages.Net Languages The future of .NetThe future of .Net

Page 4: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

What is the .Net What is the .Net FrameworkFramework Primarily a development platform Primarily a development platform

(mostly effects application (mostly effects application development)development)

Consists of two main partsConsists of two main parts– Common Language RuntimeCommon Language Runtime– .Net Framework Class Library.Net Framework Class Library

Page 5: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

CLR (Common CLR (Common Language Runtime)Language Runtime) Provides a “runtime environment” Provides a “runtime environment”

for the execution of code written for the execution of code written in ANY .Net Languagein ANY .Net Language

““Manages” Manages” – The overall execution of .Net codeThe overall execution of .Net code– Inheritance, Memory, Debugging, Inheritance, Memory, Debugging,

and application development across and application development across Multiple languages Multiple languages

Page 6: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

CLR (Continued)CLR (Continued)

Languages that utilizes the .Net framework must Languages that utilizes the .Net framework must follow the CLS follow the CLS – Common Language SpecificationCommon Language Specification– Outlines the rules and standards required or needed by Outlines the rules and standards required or needed by

the CLR to execute .Net code.the CLR to execute .Net code. The CLR will execute Managed AssembliesThe CLR will execute Managed Assemblies Intermediate Languages managed by the CLR are Intermediate Languages managed by the CLR are

called called Managed CodeManaged Code The CLR will manage for the ILThe CLR will manage for the IL

– Garbage collectionGarbage collection– Object instantiationObject instantiation– Memory allocationMemory allocation

Components written in Components written in Managed CodeManaged Code by the CLR are by the CLR are called .Net Managed assembliescalled .Net Managed assemblies

Page 7: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

.Net Managed .Net Managed AssembliesAssemblies Basic Unit of deployment of .Net Basic Unit of deployment of .Net

ApplicationsApplications Similar to the Microsoft COM ObjectsSimilar to the Microsoft COM Objects Each Managed Assembly contains a Each Managed Assembly contains a

ManifestManifest– Hold definitions of other components required Hold definitions of other components required

for execution of the applicationfor execution of the application– Prevents the problems associated with Prevents the problems associated with

conflicting DLL’sconflicting DLL’s– Revision numbers and components are listed in Revision numbers and components are listed in

the manifestthe manifest– Two versions of the same DLL can then co-existTwo versions of the same DLL can then co-exist

Page 8: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Compilation of .Net Compilation of .Net codecode All .Net languages are first compiled into an All .Net languages are first compiled into an

intermediate language called MSIL or IL intermediate language called MSIL or IL (Microsoft Intermediate Language)(Microsoft Intermediate Language)

The MSIL is then “Just In Time” (JIT) compiled at The MSIL is then “Just In Time” (JIT) compiled at first execution of the code and managed by the first execution of the code and managed by the CLRCLR

All MSIL or IL code can be compiled directly to All MSIL or IL code can be compiled directly to native code with the followingnative code with the following– Compiling native code will provide faster startup Compiling native code will provide faster startup

execution of the codeexecution of the code– Performance during execution of the code will then be Performance during execution of the code will then be

sacrificedsacrificed– During JIT Optimization is placed on the During JIT Optimization is placed on the Managed CodeManaged Code

in order to improve performance at the time of in order to improve performance at the time of executionexecution

Page 9: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

.Net Framework Class .Net Framework Class LibraryLibrary Provide a library of base classes Provide a library of base classes

that developers can use in their that developers can use in their own applications written in own applications written in ANY .Net languageANY .Net language

Because of the use of these base Because of the use of these base classes, Inheritance can then be classes, Inheritance can then be extensively used in languages extensively used in languages that use the .Net Frameworkthat use the .Net Framework

Page 10: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

.Net Languages.Net Languages

.Net applications can be written by any or a .Net applications can be written by any or a combination of many .Net languagescombination of many .Net languages

Languages includeLanguages include– VB .Net VB .Net – C#C#– J#J#– Managed C++ (default in studio is set for managed Managed C++ (default in studio is set for managed

C++)C++) Applications can be developed without the use Applications can be developed without the use

of Studio .Netof Studio .Net– Applications can be developed still using a simple Applications can be developed still using a simple

text editortext editor– ASP .Net Applications as well as other apps can be ASP .Net Applications as well as other apps can be

still developed using notepadstill developed using notepad

Page 11: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The future of the .Net The future of the .Net FrameworkFramework Standards were release in 2000 from Microsoft to the communityStandards were release in 2000 from Microsoft to the community GNU .Net is a project in the Linux community that is presently GNU .Net is a project in the Linux community that is presently

developing a CLR to run in the Linux environmentdeveloping a CLR to run in the Linux environment Languages planned to include the CLS areLanguages planned to include the CLS are

– APLAPL– COBOLCOBOL– EifelEifel– FortranFortran– HaskelHaskel– MercuryMercury– MondrianMondrian– OberonOberon– PascalPascal– PerlPerl– PythonPython– RPGRPG– SchemeScheme

Page 12: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Studio .Net Studio .Net EnvironmentEnvironmentThe IDEThe IDE

Studio .NetStudio .Net The Start PageThe Start Page Problems with Studio .Net in the Problems with Studio .Net in the

lab environmentlab environment

Page 13: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Studio .NetStudio .Net

All present .Net languages are included All present .Net languages are included under one development environmentunder one development environment– When using any one of the languages, the studio When using any one of the languages, the studio

must be used (there is no longer an environment must be used (there is no longer an environment for each language)for each language)

– You have to start a new solution/project You have to start a new solution/project Projects are containers that contain the files Projects are containers that contain the files

associated with a particular projectassociated with a particular project A solution is a container that contains one or more A solution is a container that contains one or more

projects or project containersprojects or project containers When the IDE is started you have the Projects When the IDE is started you have the Projects

tab, online resources, and My Profile tab, online resources, and My Profile

Page 14: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Start PageThe Start Page

Previous Projects

Tab for this view

Tab for Additional Help

Profile and environment settings

Start a new project

Open a project in a diff. location

Page 15: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Problems with Problems with Studio .Net Studio .Net environment in the labenvironment in the lab .Net security must allow access to the J: drive .Net security must allow access to the J: drive

or the local intra net in order to work properlyor the local intra net in order to work properly Problems arise when debugging apps on an Problems arise when debugging apps on an

ASP .Net server that is not part of the current ASP .Net server that is not part of the current domain (CLC) Basic apps will still work finedomain (CLC) Basic apps will still work fine

These problems are not present if IIS and These problems are not present if IIS and remote debugging tools are installed on the remote debugging tools are installed on the client machineclient machine– This solution is fine for students but is not practical This solution is fine for students but is not practical

for a labfor a lab– Due to security holes of IIS you can have hundreds Due to security holes of IIS you can have hundreds

of security risks on a given network.of security risks on a given network.– In the Real world situation, all apps will be placed In the Real world situation, all apps will be placed

on a server anywayon a server anyway

Page 16: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Visual Basic .NetVisual Basic .Net

General FeaturesGeneral Features Additional Features of VB .NetAdditional Features of VB .Net What has changed in VB .NetWhat has changed in VB .Net

Page 17: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

General featuresGeneral features

It is an object oriented languageIt is an object oriented language– Students do better with this subject when they have a firm understanding Students do better with this subject when they have a firm understanding

of objectsof objects– In the past VB had objects but focus was not placed on themIn the past VB had objects but focus was not placed on them– VB .Net use objects and inheritance with everythingVB .Net use objects and inheritance with everything

Uses exception handling extensivelyUses exception handling extensively– New techniques are shown to the student for providing feedback from New techniques are shown to the student for providing feedback from

their programs in order to help trouble shoot errorstheir programs in order to help trouble shoot errors– Like with most OOP languages, exceptions that are not handled will Like with most OOP languages, exceptions that are not handled will

cause programs to abnormally end or exitcause programs to abnormally end or exit Uses “generics” with creating classes and Sub programsUses “generics” with creating classes and Sub programs

– Can use the top data type on inheritance of type ObjectCan use the top data type on inheritance of type Object– Used for late binding of data types and is quite useful when Used for late binding of data types and is quite useful when

implementing stacks or queues of any data type (.Net 2.0)implementing stacks or queues of any data type (.Net 2.0) Provides a quick way to develop heavy duty applications in a Provides a quick way to develop heavy duty applications in a

windowing environmentwindowing environment It is a useful tool for developing event driven programs It is a useful tool for developing event driven programs

Page 18: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Additional Feature of Additional Feature of VB .NetVB .Net Can create both windows applications and web Can create both windows applications and web

applications at the click of a mouse buttonapplications at the click of a mouse button The interface between the Databases and applicationsThe interface between the Databases and applications

– Are the same between web apps and windows appsAre the same between web apps and windows apps– All data are transferred between the apps in XML format All data are transferred between the apps in XML format

regardless if it is a web application or a windows regardless if it is a web application or a windows applicationapplication

– A copy of the data from the database is loaded into a A copy of the data from the database is loaded into a data set. data set.

– Persistent connections between the application and the Persistent connections between the application and the database no longer existsdatabase no longer exists

Every form is a class and new forms now have to be Every form is a class and new forms now have to be instantiatedinstantiated

VB .Net is still not case sensitiveVB .Net is still not case sensitive

Page 19: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

What is Not in VB .NetWhat is Not in VB .Net

Data ControlsData Controls– Because of the different way that the apps connect Because of the different way that the apps connect

to the database, there is no longer the support of to the database, there is no longer the support of data controls in VB .Netdata controls in VB .Net

– Persistent connections with the database is no Persistent connections with the database is no longer presentlonger present

Object instantiation is now done differentlyObject instantiation is now done differently Garbage collection for references that lose Garbage collection for references that lose

there objects are done periodically not when there objects are done periodically not when the reference lose its scopethe reference lose its scope

Periodic changes throughout the language Periodic changes throughout the language making it vastly different from VB 6.0 in order making it vastly different from VB 6.0 in order to make it compliant to the .Net Framework to make it compliant to the .Net Framework and the CLSand the CLS

Page 20: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Introduction to The Introduction to VB .NetVB .Net Data Types in VB .NetData Types in VB .Net Functions and Sub ProceduresFunctions and Sub Procedures Practice ExamplesPractice Examples

Page 21: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Data Types in VB .NetData Types in VB .Net

Data Types and possible valuesData Types and possible values– Integer -> -2,147,483,648 (4 bytes)Integer -> -2,147,483,648 (4 bytes)– Double -> floating point numbers with 14 digits of accuracy Double -> floating point numbers with 14 digits of accuracy

(8 Bytes)(8 Bytes)

– Decimal -> decimal values ( 16 bytes replaced currency in 6.0)Decimal -> decimal values ( 16 bytes replaced currency in 6.0)– Date -> the date (8 Bytes)Date -> the date (8 Bytes)– Byte -> 0 to 255 (1 Byte)Byte -> 0 to 255 (1 Byte)– Char -> Unicode character (2 Bytes)Char -> Unicode character (2 Bytes)– Boolean ->True or false value (2 Bytes)Boolean ->True or false value (2 Bytes)– Single -> floating point number with 6 digits of accuracy (4 Single -> floating point number with 6 digits of accuracy (4

bytes)bytes)– Short -> 2 byte integerShort -> 2 byte integer– Long -> 8 byte integerLong -> 8 byte integer– String -> an arrangement of alpha-numeric characters varies in String -> an arrangement of alpha-numeric characters varies in

lengthlength– Object -> any data type 4 bytesObject -> any data type 4 bytes

Page 22: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Functions and Sub Functions and Sub procedures / Programs in procedures / Programs in VB .Net (Methods)VB .Net (Methods) Functions and sub procedures must either have a sub Functions and sub procedures must either have a sub

or function keyword in the function or sub procedure or function keyword in the function or sub procedure headingheading

They can be either public or private (following the They can be either public or private (following the same conventions in OOP languages such as C++ or same conventions in OOP languages such as C++ or Java)Java)

All parameters are passed by value by default in All parameters are passed by value by default in VB .NetVB .Net

Parameters of any data type may be passed by Parameters of any data type may be passed by referencereference

All Objects and arrays are passed by reference not All Objects and arrays are passed by reference not valuevalue

All events are handled by a sub procedure in VB .NetAll events are handled by a sub procedure in VB .Net Functions return a value and Sub Procedures do NotFunctions return a value and Sub Procedures do Not

Page 23: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice examplePractice example 1 1

You can use the text book given to you You can use the text book given to you to get the basics needed in to get the basics needed in programming VB starting on page 477programming VB starting on page 477

Getting familiar with VB .NetGetting familiar with VB .Net– Write a program that will take text from Write a program that will take text from

one text box and place that text in another one text box and place that text in another text box with a click of a buttontext box with a click of a button

– Take a look at the attributes of each controlTake a look at the attributes of each control A control can be a button text box etc.A control can be a button text box etc. Each control should contain names that follow Each control should contain names that follow

VB specifications i.e. txtBox1 txtBox2 btnMoveVB specifications i.e. txtBox1 txtBox2 btnMove Each name as always should be meaningfullEach name as always should be meaningfull

Page 24: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice Example 2Practice Example 2

Using Functions in VB .NetUsing Functions in VB .Net– Use the text boxes from the previous exampleUse the text boxes from the previous example– Add a text boxAdd a text box– Provide a function that adds the values of text Provide a function that adds the values of text

box 1 and text box 2box 1 and text box 2– Place the answer in text box3Place the answer in text box3– Use variables of type double and use the Use variables of type double and use the

CDbl() function to convert the string value of CDbl() function to convert the string value of the text box to a double the text box to a double page 485 page 485 in your textin your text

Page 25: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Loops and control Loops and control structuresstructures The If StatementThe If Statement The Select Case StatementThe Select Case Statement The Do While and Loop While The Do While and Loop While

loopsloops The For LoopThe For Loop

Page 26: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The IF StatementThe IF Statement

Every If statement must contain a then and an end ifEvery If statement must contain a then and an end if Example:Example:

– If Num1 < 2 ThenIf Num1 < 2 ThenMessageBox.show(“The value is less than 2”) MessageBox.show(“The value is less than 2”)

End IfEnd If– If Num1 <> 4 thenIf Num1 <> 4 then

MessageBox.Show(“The value is not 4”)MessageBox.Show(“The value is not 4”)

End IfEnd If The relational operators that can be used in VB areThe relational operators that can be used in VB are

– >>– <<– ==– >=>=– <=<=– <> (Not equal to)<> (Not equal to)

Page 27: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Select Case The Select Case statementstatement

The select case statement is a lot like The select case statement is a lot like the switch statement in Javathe switch statement in Java

It can use ANY data type in VBIt can use ANY data type in VB ExampleExample

Select Case Num1Select Case Num1Case 1 DoSomeThing()Case 1 DoSomeThing()Case 2 Do SomethingElse()Case 2 Do SomethingElse()

End SelectEnd Select Yes you can use strings as wellYes you can use strings as well

Page 28: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Do While LoopsDo While Loops

Do while loops evaluate the Do while loops evaluate the expression first then executes the expression first then executes the Loop BodyLoop Body

Act much in the same as All While Act much in the same as All While loops in languages like C++ and Javaloops in languages like C++ and Java

ExampleExampleDo While Num1 < 10Do While Num1 < 10

Num1 += 1Num1 += 1LoopLoop

Page 29: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Loop While LoopsLoop While Loops

The Body of the Loop is executed first The Body of the Loop is executed first then the expression is evaluatedthen the expression is evaluated

The loop will execute at least onceThe loop will execute at least once This is a lot like the do while loop in This is a lot like the do while loop in

Java and students get confused with Java and students get confused with this subtle changethis subtle change

ExampleExampleDoDo

Num1 += 1Num1 += 1Loop While Num1 < 10Loop While Num1 < 10

Page 30: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

End Of Day 1End Of Day 1

Page 31: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

VB .Net Seminar Day 2VB .Net Seminar Day 2

June 8, 2004June 8, 2004

Page 32: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Microsoft SQL ServerMicrosoft SQL Server

MS SQL BasicsMS SQL Basics The Enterprise ManagerThe Enterprise Manager Creating DatabasesCreating Databases Connecting to DatabasesConnecting to Databases The use of the Data SetThe use of the Data Set Exception HandlingException Handling

Page 33: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Microsoft SQL BasicsMicrosoft SQL Basics

Differences between MS SQL and Differences between MS SQL and AccessAccess

Advantages of MS SQLAdvantages of MS SQL Quirky things with SQLQuirky things with SQL Connecting to the database with Connecting to the database with

the managerthe manager

Page 34: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Differences between Differences between MS SQL and AccessMS SQL and Access SQL More Powerful than MS SQL More Powerful than MS

AccessAccess– Larger data types are availableLarger data types are available– Connection over a network provide Connection over a network provide

access to multiple clientsaccess to multiple clients– Blob data type availableBlob data type available

A client is required to connect to A client is required to connect to the SQL Databasethe SQL Database

Page 35: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Advantages of MS SQLAdvantages of MS SQL

Can handle multiple users at one Can handle multiple users at one timetime

Ideal for web sites and web Ideal for web sites and web applicationsapplications

Contain the BLOB (Binary Large Contain the BLOB (Binary Large Object) which enables a user to Object) which enables a user to store images in a databasestore images in a database

Larger numeric values can be Larger numeric values can be stored in each field stored in each field

Page 36: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Quirky problems with Quirky problems with SQLSQL No Auto Number Data Type in MS SQLNo Auto Number Data Type in MS SQL Auto number is an integer data typeAuto number is an integer data type Identity is set to yesIdentity is set to yes And the seed is set to oneAnd the seed is set to one This gives you the option to set the This gives you the option to set the

starting number and the increment starting number and the increment you want the auto number to haveyou want the auto number to have

Page 37: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Enterprise ManagerEnterprise Manager

Connecting to the databaseConnecting to the database Getting through the confusion of Getting through the confusion of

locating databaseslocating databases Defining the different containers Defining the different containers

in the Managerin the Manager

Page 38: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Connecting to the Connecting to the DBMSDBMS Start the Enterprise ManagerStart the Enterprise Manager

Right Click SQL Server groupRight Click SQL Server group

Page 39: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Connecting to the Connecting to the DBMSDBMS Click on SQL Click on SQL

Server RegistrationServer Registration Click nextClick next In the text box In the text box

labeled Available labeled Available Servers type Servers type Sigma.vbnet.matcSigma.vbnet.matcmp.ncc.edump.ncc.edu

Click Add then nextClick Add then next

Page 40: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Connecting to the Connecting to the DBMSDBMS Click on SQL Server loginClick on SQL Server login Username is the first six letters of Username is the first six letters of

your last name and your first initialyour last name and your first initial Password is vbnetPassword is vbnet Click next and click next againClick next and click next again Click FinishClick Finish Click close on the next dialog boxClick close on the next dialog box

Page 41: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Getting through the Getting through the concussionconcussion MS SQL Enterprise Manager will MS SQL Enterprise Manager will

display ALL of the databases located display ALL of the databases located on the serveron the server

Access to each database is controlled Access to each database is controlled by the DBMSby the DBMS

ALL tables are displayed in each ALL tables are displayed in each databasedatabase

This includes tables that are used by This includes tables that are used by the DBMSthe DBMS

Page 42: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Containers in SQLThe Containers in SQL

Each Each container has container has a specific rolea specific role

Student Student Databases Databases are in the are in the databases databases containercontainer

Page 43: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Database ContainerDatabase Container

Every students Every students database is displayeddatabase is displayed

Only the database Only the database that the student has that the student has permissions for can permissions for can be openedbe opened

Click on the database Click on the database container with your container with your usernameusername

Page 44: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Student Database Student Database containercontainer

Page 45: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Creating the DatabaseCreating the Database

Creating tablesCreating tables Properties of the data typesProperties of the data types Entering and Displaying Data in Entering and Displaying Data in

database Tablesdatabase Tables

Page 46: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Creating TablesCreating Tables

Right click on the table containerRight click on the table container Click new tableClick new table This is a lot like the Access This is a lot like the Access

interface with different data types. interface with different data types. At this points explore the interface At this points explore the interface

and notice the differencesand notice the differences

Page 47: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Properties of Data Properties of Data FieldsFields Each Data Field has a length propertyEach Data Field has a length property This sometimes causes a problem with This sometimes causes a problem with

students who make this field too smallstudents who make this field too small Each data Field can also allow null Each data Field can also allow null

valuesvalues After defining each column and setting After defining each column and setting

all the properties set the primary key all the properties set the primary key by right clicking on the field that is to by right clicking on the field that is to be the keybe the key

Page 48: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Entering and Entering and Displaying DataDisplaying Data Right Click the tableRight Click the table Click Open TableClick Open Table Click Return All RowsClick Return All Rows From here you can view and enter From here you can view and enter

new data into the tablenew data into the table

Page 49: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice Example 1Practice Example 1

Creating a Table in VB .NetCreating a Table in VB .Net Create a table of customers in a hardware Create a table of customers in a hardware

storestore Columns will includeColumns will include

– Customer IDCustomer ID– First NameFirst Name– Last NameLast Name– AddressAddress– Zip CodeZip Code

Fill the table with dataFill the table with data Display that dataDisplay that data

Page 50: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Connecting to the Connecting to the database with VB .Net database with VB .Net ApplicationsApplications The Data ProviderThe Data Provider The Data SetThe Data Set The use of the wizardThe use of the wizard

Page 51: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Data AdapterThe Data Adapter

Needed to connect to every DBMSNeeded to connect to every DBMS Must Use the Adapter that Must Use the Adapter that

represents the DBMS you are represents the DBMS you are going to usegoing to use

We are going to use the We are going to use the SQLDataAdapter ObjectSQLDataAdapter Object

Holds the information on how toHolds the information on how to

Page 52: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Data ProviderThe Data Provider

Manipulates data through the use of Manipulates data through the use of SQL statements or commandsSQL statements or commands

Hold connection information to the Hold connection information to the DatabaseDatabase

Contain two Major componentsContain two Major components– Data Adapter Object – updates data in the Data Adapter Object – updates data in the

datasetdataset– Connection Object – maintains the Connection Object – maintains the

connectionconnection

Page 53: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Data SetThe Data Set

Holds data returned from a Holds data returned from a procedure or Query performed by procedure or Query performed by the data adapterthe data adapter

Provides a local “Copy” of the Provides a local “Copy” of the data from the table on the local data from the table on the local machinemachine

Prevents persistent connections Prevents persistent connections with the database and reduces with the database and reduces network trafficnetwork traffic

Page 54: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The use of the wizardThe use of the wizard

Give Demo on using the wizardGive Demo on using the wizard

Page 55: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The Data SetThe Data Set

Generating the data set objectGenerating the data set object The use of the onload event The use of the onload event

handlerhandler Binding controlsBinding controls Creating navigation for a Creating navigation for a

databasedatabase

Page 56: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Generating the Data Generating the Data Set ObjectSet Object Once the Data Adapter and the Once the Data Adapter and the

connection object is created click connection object is created click on Data in the menuon Data in the menu

Click generate dataset Click generate dataset Give a name to the datasetGive a name to the dataset Click OKClick OK

Page 57: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

The use of the onLoad The use of the onLoad event Handlerevent Handler Double click the formDouble click the form Place the fill method in the Load Place the fill method in the Load

event handlerevent handler This will fill the dataset object with This will fill the dataset object with

the data from the table when the the data from the table when the form loadsform loads

ExampleExample

SQLDataAdapter1.Fill(MyDataSet1)SQLDataAdapter1.Fill(MyDataSet1)

Page 58: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Binding ControlsBinding Controls

Once you create a data set you can Once you create a data set you can then bind the controls of the form to then bind the controls of the form to fields or columns of the database tablefields or columns of the database table

This is done with in the Bindings This is done with in the Bindings property in the text box properties property in the text box properties sheetsheet

Under the bindings property click text Under the bindings property click text and then the field you wish to bind to and then the field you wish to bind to the text boxthe text box

Page 59: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Creating navigation for Creating navigation for a databasea database Managed by the BindingManagerBase ObjectManaged by the BindingManagerBase Object This object contains the Position Property the This object contains the Position Property the

holds the current position of the record in the holds the current position of the record in the datasetdataset

This is done by adding one to the position This is done by adding one to the position attribute of the objectattribute of the object

Methods of this object includesMethods of this object includes– Addnew()Addnew()– EndCurrentEdit()EndCurrentEdit()– CancelCurrentEdit() -> provides a role back featureCancelCurrentEdit() -> provides a role back feature– RemoveAt() -> deletes current row at given RemoveAt() -> deletes current row at given

positionposition

Page 60: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Exception Handling Exception Handling ImplementationImplementation Use try catch block much the same in JavaUse try catch block much the same in Java Can help trouble shoot connections to Can help trouble shoot connections to

databasesdatabases Very important to use when filling the datasetVery important to use when filling the dataset ExampleExampleTryTry SqlDataAdapter1.Fill(DataSet11)SqlDataAdapter1.Fill(DataSet11)CatchCatch ex ex AsAs Exception Exception MessageBox.Show("Error will dataset fill")MessageBox.Show("Error will dataset fill")EndEnd TryTry

Page 61: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice Example 2Practice Example 2

Connecting a form to your Hardware Connecting a form to your Hardware customerscustomers

Create a form with text fields for each columnCreate a form with text fields for each column– Create the data Adapter and Data Connection with Create the data Adapter and Data Connection with

the use of the wizardthe use of the wizard– Create the data set objectCreate the data set object– Create the onload event handler to fill the data setCreate the onload event handler to fill the data set– Bind your controlsBind your controls– Be sure to use exception handling for filling the data Be sure to use exception handling for filling the data

setset– Create a Next button to navigate to the next record Create a Next button to navigate to the next record

in the databasein the database

Page 62: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

End Of Day 2End Of Day 2

Page 63: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

VB .Net Seminar Day 3VB .Net Seminar Day 3

June 9, 2004June 9, 2004

Page 64: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

TopicsTopics

Adding and Editing RecordsAdding and Editing Records Updates and deletes with Bound controlsUpdates and deletes with Bound controls Classes and Modules in VB .NetClasses and Modules in VB .Net MenusMenus From designFrom design MDI (Multi Document Interfaces)MDI (Multi Document Interfaces) Bound and unbound controls in VB .netBound and unbound controls in VB .net Why Unbound controls are usedWhy Unbound controls are used

Page 65: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Adding and Editing Adding and Editing RecordsRecords When Adding recordsWhen Adding records

– The Position of the dataset should be set to The Position of the dataset should be set to the endthe end

– The text boxes should be clearedThe text boxes should be cleared The AddNew() Method accomplishes all The AddNew() Method accomplishes all

this in one method callthis in one method call The AddNew() Method is part of the The AddNew() Method is part of the

BindingManagerBase ObjectBindingManagerBase Object When changes are being made, a cancel When changes are being made, a cancel

button should be provided to “Roll Back” button should be provided to “Roll Back” changes made to the data setchanges made to the data set

Page 66: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

EditEdit

When Navigating the database the When Navigating the database the Text boxes should be disabled to Text boxes should be disabled to prevent changesprevent changes

There should be an edit button thatThere should be an edit button that– Disables the navigation buttonDisables the navigation button– Enables the text boxes for editingEnables the text boxes for editing– Provide a cancel button that “Roles Back” Provide a cancel button that “Roles Back”

the changes that are made by calling the the changes that are made by calling the CancelCurrentEdit() method of the CancelCurrentEdit() method of the BindingManagerBase ObjectBindingManagerBase Object

Page 67: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Update and Deleting Update and Deleting RecordsRecords This is done byThis is done by

– Ending the current edit by calling EndCurrentEdit() Ending the current edit by calling EndCurrentEdit() in the BindingManagerBase classin the BindingManagerBase class

– Updating the DB with Update() in the data adapterUpdating the DB with Update() in the data adapter– Cause the dataset to reflect the changes by calling Cause the dataset to reflect the changes by calling

the AcceptChanges() method in the data setthe AcceptChanges() method in the data set Deleting the recordsDeleting the records

– First Ask the user if they are sure they want to First Ask the user if they are sure they want to deletedelete

– Use the RemoveAt() method of the Use the RemoveAt() method of the BindingManagerBase objectBindingManagerBase object

– Update the database with the Update() methodUpdate the database with the Update() method– Have the dataset reflect the change by calling the Have the dataset reflect the change by calling the

AcceptChanges() method of the dataset objectAcceptChanges() method of the dataset object

Page 68: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice Example 1Practice Example 1

With the Example finished With the Example finished yesterdayyesterday– Add an Add ButtonAdd an Add Button– Add an Edit ButtonAdd an Edit Button– Provide a Save and a delete featureProvide a Save and a delete feature– Use exception handling for Use exception handling for

everythingeverything

Page 69: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Classes and Modules in Classes and Modules in VB .NetVB .Net Creating classes in VB .NetCreating classes in VB .Net The constructor and Sub The constructor and Sub

procedures in VB .Netprocedures in VB .Net The use of Modules The use of Modules

Page 70: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Creating Classes in Creating Classes in VB .NetVB .Net Classes can be added to a project byClasses can be added to a project by

– Right clicking the project containerRight clicking the project container– Click addClick add– Click add classClick add class

As in Most OOP Languages VB classes As in Most OOP Languages VB classes havehave– Public and private attributesPublic and private attributes– Public and private Methods (called functions Public and private Methods (called functions

or sub procedures)or sub procedures)– Constructors and Destructors (destructors Constructors and Destructors (destructors

are not really needed in VB because of are not really needed in VB because of garbage collection)garbage collection)

Page 71: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

ModulesModules

Modules can also be added to a Modules can also be added to a project to provide a place for project to provide a place for “Global” Methods and Identifiers“Global” Methods and Identifiers

These Identifiers and methods These Identifiers and methods can be either public or privatecan be either public or private

Public Identifiers and methods Public Identifiers and methods can be accessed from all of the can be accessed from all of the forms and classes in the VB forms and classes in the VB projectproject

Page 72: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice ExamplePractice Example

For this ExampleFor this Example– Create an Auto ClassCreate an Auto Class– An Auto will haveAn Auto will have

Three AttributesThree Attributes Three MethodsThree Methods Two constructorsTwo constructors

– Try instantiating the method in the Try instantiating the method in the formform

Page 73: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

MenusMenus

When adding menus to a form When adding menus to a form you can type in the choice right you can type in the choice right into the menu objectinto the menu object

Click event handlers can then be Click event handlers can then be added for each menu choice in added for each menu choice in the same manner as the buttonthe same manner as the button

Page 74: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Form DesignForm Design

Colors are importantColors are important– They should be contrast in colorThey should be contrast in color– Ease to readEase to read– Easy on the eyes for long periods of Easy on the eyes for long periods of

viewingviewing Should provide easy navigationShould provide easy navigation Should provide a way to enter the data Should provide a way to enter the data

easily with just using the keyboardeasily with just using the keyboard

Page 75: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Multi Document Multi Document Interfaces (MDI)Interfaces (MDI) When creating a form in VB .Net you are When creating a form in VB .Net you are

creating a classcreating a class Every class in vb must be instantiated before it Every class in vb must be instantiated before it

is usedis used This is accomplished by using the new This is accomplished by using the new

keywordkeyword When the instance of the form is created, the When the instance of the form is created, the

form can then be visible by calling the forms form can then be visible by calling the forms show methodshow method

Closing a form does not exit the program. To Closing a form does not exit the program. To exit the program the End method should be exit the program the End method should be calledcalled

Page 76: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Practice Example 3Practice Example 3

Create a Form that will be a Create a Form that will be a switch boardswitch board– Add a form to yesterdays exampleAdd a form to yesterdays example– Place a button that will open the Place a button that will open the

customer formcustomer form– Place a button that will exit the Place a button that will exit the

programprogram

Page 77: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

Bound and Unbound Bound and Unbound ControlsControls So far we have seen the benefits of bound So far we have seen the benefits of bound

controlscontrols These are ok if you intend to use the same These are ok if you intend to use the same

SQL query for the whole applicationSQL query for the whole application Once controls are bound to a data set, Once controls are bound to a data set,

changes to the query in the data adapter can changes to the query in the data adapter can not be accomplishednot be accomplished

Unbounded controls give you the power to Unbounded controls give you the power to create new data adapters with new queries.create new data adapters with new queries.

Values can then be placed into the query to Values can then be placed into the query to find specific records in a databasefind specific records in a database

Page 78: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

End Day 3End Day 3

Page 79: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

VB .Net Seminar Day 4VB .Net Seminar Day 4

June 10, 2004June 10, 2004

Page 80: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

TopicsTopics

ASP .Net basic applicationsASP .Net basic applications ASP .Net Database applicationsASP .Net Database applications Web FormsWeb Forms Crystal ReportsCrystal Reports Creating Help FilesCreating Help Files Demo with Serial port programming and Demo with Serial port programming and

VB .NetVB .Net Handout CertificatesHandout Certificates

Page 81: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

ASP .Net basic ASP .Net basic ApplicationsApplications

Page 82: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and
Page 83: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and
Page 84: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and
Page 85: Visual Basic.Net Seminar June 7, 2004. Topics Today include  The.Net Framework  Studio.Net Environment  VB.Net  Introduction to VB.Net  Loops and

End Day 4End Day 4