Page 1 of 37 VISUAL BASIC TOPICS Object-Oriented Programming Concepts Classes Objects Encapsulation Inheritance Polymorphism Introduction to the Visual Basic Programming Program and Graphical User Interface Design B. Variables and Calculations C. Decision and Repetition Structures D. Arrays and Structures E. Procedures and Functions Multiple Forms Splash screens About forms Summary forms Database DataTables, DataViews and Datasets. Data Binding to Visual Basic objects Parent Child relationships Printing Documents Common Dialog controls PrintDocument control Crystal Reports Programming for the Web Web services Data driven web applications VISUAL STUDIO TOPICS In this section 64-Bit Visual Basic for Applications Overview Avoiding Naming Conflicts Calling Procedures with the Same Name Calling Property Procedures Calling Sub and Function Procedures Creating Object Variables Creating Recursive Procedures Declaring Arrays Declaring Constants Declaring Variables Executing code when setting properties Looping Through Code Making Faster For...Next Loops Passing Arguments Efficiently Returning Strings from Functions Understanding Automation Understanding Conditional Compilation Understanding Named Arguments and Optional Arguments Understanding Objects, Properties, Methods, and Events Understanding Parameter Arrays Understanding Scope and Visibility Understanding the Lifetime of Variables Understanding Variants Understanding Visual Basic Syntax Using Arrays Using Constants
37
Embed
VISUAL BASIC TOPICS VISUAL STUDIO TOPICS · 03/05/2018 · Page 1 of 37 VISUAL BASIC TOPICS Object -Oriented Programming Concepts In this section Classes Objects Encapsulation Inheritance
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 of 37
VISUAL BASIC TOPICS
Object-Oriented Programming Concepts
Classes
Objects
Encapsulation
Inheritance
Polymorphism
Introduction to the Visual Basic Programming
Program and Graphical User Interface Design
B. Variables and Calculations
C. Decision and Repetition Structures
D. Arrays and Structures
E. Procedures and Functions
Multiple Forms
Splash screens
About forms
Summary forms
Database
DataTables, DataViews and Datasets.
Data Binding to Visual Basic objects
Parent Child relationships
Printing Documents
Common Dialog controls
PrintDocument control
Crystal Reports
Programming for the Web
Web services
Data driven web applications
VISUAL STUDIO TOPICS
In this section 64-Bit Visual Basic for Applications Overview Avoiding Naming Conflicts Calling Procedures with the Same Name Calling Property Procedures Calling Sub and Function Procedures Creating Object Variables Creating Recursive Procedures Declaring Arrays Declaring Constants Declaring Variables Executing code when setting properties Looping Through Code Making Faster For...Next Loops Passing Arguments Efficiently Returning Strings from Functions Understanding Automation Understanding Conditional Compilation Understanding Named Arguments and Optional Arguments Understanding Objects, Properties, Methods, and Events Understanding Parameter Arrays Understanding Scope and Visibility Understanding the Lifetime of Variables Understanding Variants Understanding Visual Basic Syntax Using Arrays Using Constants
Page 2 of 37
VISUAL STUDIO TOPICS
Using Data Types Efficiently Using Do...Loop Statements Using For Each...Next Statements Using For...Next Statements Using If...Then...Else Statements Using Parentheses in Code Using Select Case Statements Using the Add-In Manager Using With Statements Visual Basic Naming Rules Working Across Applications Writing a Function Procedure Writing a Property Procedure Writing a Sub Procedure Writing Assignment Statements Writing Data to Files Writing Declaration Statements Writing Executable Statements Writing Visual Basic Statements
Page 3 of 37
SQL COMMANDS SQL Query Types
SELECT Statement Retrieve records from a table
SELECT LIMIT Statement Retrieve records from a table and limit results
SELECT TOP Statement Retrieve records from a table and limit results
INSERT Statement Insert records into a table
UPDATE Statement Update records in a table
DELETE Statement Delete records from a table
TRUNCATE TABLE Statement Delete all records from a table (no rollback)
UNION Operator Combine 2 result sets (removes duplicates)
UNION ALL Operator Combine 2 result sets (includes duplicates)
INTERSECT Operator Intersection of 2 result sets
MINUS Operator Result set of one minus the result set of another
EXCEPT Operator Result set of one minus the result set of another
SQL Comparison Operators
Comparison Operators Operators such as =, <>, !=, >, <, and so on
SQL Joins
JOIN Tables Inner and Outer joins
SQL Aliases
ALIASES Create a temporary name for a column or table
SQL Clauses
DISTINCT Clause Retrieve unique records
FROM Clause List tables and join information
WHERE Clause Filter results
ORDER BY Clause Sort query results
GROUP BY Clause Group by one or more columns
HAVING Clause Restrict the groups of returned rows
SQL Functions
COUNT Function Return the count of an expression
Page 4 of 37
SUM Function Return the sum of an expression
MIN Function Return the min of an expression
MAX Function Return the max of an expression
AVG Function Return the average of an expression
SQL Conditions
AND Condition 2 or more conditions to be met
OR Condition Any one of the conditions are met
AND & OR Combining AND and OR conditions
LIKE Condition Use wildcards in a WHERE clause
IN Condition Alternative to multiple OR conditions
NOT Condition Negate a condition
IS NULL Condition Test for NULL value
IS NOT NULL Condition Test for NOT NULL value
BETWEEN Condition Retrieve within a range (inclusive)
EXISTS Condition Condition is met if subquery returns at least one row
SQL Tables and Views
CREATE TABLE Create a table
CREATE TABLE AS Create a table from another table's definition and data
ALTER TABLE Add, modify or delete columns in a table; rename a table
DROP TABLE Delete a table
GLOBAL TEMP Tables Tables that are distinct within SQL session
LOCAL TEMP Tables Tables that are distinct within modules and embedded SQL program
SQL VIEW Virtual tables (views of other tables)
SQL Keys, Constraints and Indexes
Primary Keys Create or drop primary keys
Indexes Create and drop indexes (performance tuning)
SQL Data Types
Data Types Data Types in SQL
SQL Programming
Page 5 of 37
Comments How to create comments within your SQL statement
Objectives
Over the course of the past 12 days, you have examined every major topic used to write powerful queries to retrieve
data from a database. You have also briefly explored aspects of database design and database security. Today's purpose
is to cover advanced SQL topics, which include the following:
Temporary tables
Cursors
Stored procedures
Triggers
Embedded SQL
NOTE: Today's examples use Oracle7's PL/SQL and Microsoft/Sybase SQL Server's Transact-SQL implementations. We
made an effort to give examples using both flavors of SQL wherever possible. You do not need to own a copy of either
the Oracle7 or the SQL Server database product. Feel free to choose your database product based on your requirements.
(If you are reading this to gain enough knowledge to begin a project for your job, chances are you won't have a choice.)
NOTE: Although you can apply most of the examples within this book to any popular database management system, this
statement does not hold for all the material covered today. Many vendors still do not support temporary tables, stored
procedures, and triggers. Check your documentation to determine which of these features are included with your
favorite database system.
Temporary Tables
The first advanced topic we discuss is the use of temporary tables, which are simply tables that exist temporarily within
a database and are automatically dropped when the user logs out or their database connection ends. Transact-SQL
creates these temporary tables in the tempdb database. This database is created when you install SQL Server. Two types
of syntax are used to create a temporary table.
SYNTAX:
SYNTAX 1:
create table #table_name (
field1 datatype,
.
.
.
Page 6 of 37
fieldn datatype)
Syntax 1 creates a table in the tempdb database. This table is created with a unique name consisting of a combination of
the table name used in the CREATE TABLE command and a date-time stamp. A temporary table is available only to its
creator. Fifty users could simultaneously issue the following commands:
1> create table #albums (
2> artist char(30),
3> album_name char(50),
4> media_type int)
5> go
The pound sign (#) before the table's name is the identifier that SQL Server uses to flag a temporary table. Each of the
50 users would essentially receive a private table for his or her own use. Each user could update, insert, and delete
records from this table without worrying about other users invalidating the table's data. This table could be dropped as
usual by issuing the following command:
1> drop table #albums
2> go
The table could also be dropped automatically when the user who created it logs out of the SQL Server. If you created
this statement using some type of dynamic SQL connection (such as SQL Server's DB-Library), the table will be deleted
when that dynamic SQL connection is closed.
Syntax 2 shows another way to create a temporary table on an SQL Server. This syntax produces a different result than
the syntax used in syntax 1, so pay careful attention to the syntactical differences.
SYNTAX:
SYNTAX 2:
create table tempdb..tablename (
field1 datatype,
.
.
.
fieldn datatype)
Creating a temporary table using the format of syntax 2 still results in a table being created in the tempdb database.
Page 7 of 37
This table's name has the same format as the name for the table created using syntax 1. The difference is that this table
is not dropped when the user's connection to the database ends. Instead, the user must actually issue a DROP TABLE
command to remove this table from the tempdb database.
TIP: Another way to get rid of a table that was created using the create table tempdb..tablename syntax is to shut down
and restart the SQL Server. This method removes all temporary tables from the tempdb database.
Examples 13.1 and 13.2 illustrate the fact that temporary tables are indeed temporary, using the two different forms of
syntax. Following these two examples, Example 13.3 illustrates a common usage of temporary tables: to temporarily
store data returned from a query. This data can then be used with other queries.
You need to create a database to use these examples. The database MUSIC is created with the following tables:
ARTISTS
MEDIA
RECORDINGS
Use the following SQL statements to create these tables:
INPUT:
1> create table ARTISTS (
2> name char(30),
3> homebase char(40),
4> style char(20),
5> artist_id int)
6> go
1> create table MEDIA (
2> media_type int,
3> description char(30),
4> price float)
5> go
1> create table RECORDINGS (
2> artist_id int,
Page 8 of 37
3> media_type int,
4> title char(50),
5> year int)
6> go
NOTE: Tables 13.1, 13.2, and 13.3 show some sample data for these tables.
Table 13.1. The ARTISTS table.
Name Homebase Style Artist_ID
Soul Asylum Minneapolis Rock 1
Maurice Ravel France Classical 2
Dave Matthews Band Charlottesville Rock 3
Vince Gill Nashville Country 4
Oingo Boingo Los Angeles Pop 5
Crowded House New Zealand Pop 6
Mary Chapin-Carpenter Nashville Country 7
Edward MacDowell U.S.A. Classical 8
Table 13.2. The MEDIA table.
Media_Type Description Price
1 Record 4.99
2 Tape 9.99
3 CD 13.99
4 CD-ROM 29.99
5 DAT 19.99
Table 13.3. The RECORDINGS table.
Artist_Id Media_Type Title Year
1 2 Hang Time 1988
1 3 Made to Be Broken 1986
2 3 Bolero 1990
3 5 Under the Table and Dreaming 1994
4 3 When Love Finds You 1994
Page 9 of 37
5 2 Boingo 1987
5 1 Dead Man's Party 1984
6 2 Woodface 1990
6 3 Together Alone 1993
7 5 Come On, Come On 1992
7 3 Stones in the Road 1994
8 5 Second Piano Concerto 1985
Example 13.1
You can create a temporary table in the tempdb database. After inserting a dummy record into this table, log out. After
logging back into SQL Server, try to select the dummy record out of the temporary table. Note the results:
INPUT:
1> create table #albums (
2> artist char(30),
3> album_name char(50),
4> media_type int)
5> go
1> insert #albums values ("The Replacements", "Pleased To Meet Me", 1)
2> go
Now log out of the SQL Server connection using the EXIT (or QUIT) command. After logging back in and switching to the
database you last used, try the following command:
INPUT:
1> select * from #albums
2> go
ANALYSIS:
This table does not exist in the current database.
Example 13.2
Now create the table with syntax 2:
Page 10 of 37
INPUT:
1> create table tempdb..albums (
2> artist char(30),
3> album_name char(50),
4> media_type int)
5> go
1> insert #albums values ("The Replacements", "Pleased To Meet Me", 1)
2> go
After logging out and logging back in, switch to the database you were using when create table tempdb..albums() was