Title: JDS VB'NET Skill Session
1JDS VB.NET Skill Session
- Fall 2004
- Presented by YUHAO LIN
2TOPICS
- Visual Studio .NET
- VB.NET Code Structure
- VB.NET Language Basics
- Data Access in .NET
3What is .NET ?
- Microsoft .NET (released 2001) is Microsofts
new generation "software platform." It's a
language-neutral environment for writing programs - Program in any language, run on one operating
system - Includes comprehensive class libraries that
provide rich features
4What is VB.NET ?
- Visual Basic .NET
- Next generation of Visual Basic
- A programming language in the .NET framework
- Fully object-oriented
5Visual Studio .NET
- Available in Software Lab
- Latest version 2003
- Integrated Development Environment (IDE) for
developing .NET applications
6Visual Studio .NET
- Create a new project
- Opening an existing project
- Open .sln file
- Solution Explorer (design vs code view)
- Properties Window
- Toolbox many Controls
- Task List
7Visual Studio .NET
- Code view
- Comments
- Regions collapse
- Intellisense
- Run / compile
- Debug / step into
- Executable file
- Location bin or obj subdirectory
8VB.NET Code Structure
- VB.NET
- Import statements
- Namespace
- Class
- Functions / Subs
- Properties
- Class variables
- Java
- Package
- Import statements
- Class
- Methods
- Accessor methods
- Class variables
9VB.NET Code Structure
- VB.NET
- imports System.Data.OleDb
- namespace TestNamespace
- public class TestClass
- sub NewRecord()
- end sub
- function GetRecord() as String
-
- return strX
- end function
- End class
- end namespace
Java package com.deitel.chp08 import
java.io. public class Driver void
newRecord() String getRecord()
return strX
10VB.NET Language
- Case insensitive
- BUT, always be consistent !!!!!
- No semicolon to end statement
- One line per statement, _ for multi-line
statements - str1 str2 _ str1 str2 str3
- str3
- Very wordy, resembles English language
- Good for beginners
11Programming Review
- Car myCar new Car(Ford, Escort)
- What did I do ??
12Common Data Types
- Integer
- Double
- Boolean
- String
- Array
Dim j as integer 0 Dim d as double -3.55 Dim
b as boolean false Dim s as string Yo
! Dim Days( ) As Integer New Integer(6) 1,
2, 3, 4, 5, 6, 7 create an array with 7
elements, starting at index 0 end at 6
13Data Conversion
- Convert.ToType(var)
- Ex Convert.ToInt32(45)
- Convert.ToDateTime(12/31/2000)
- Ex
- Dim j as integer
- Dim s as string 16
- If IsNumeric(s) Then check if s is a valid
number - J Convert.ToInt32(s) convert s to 32-bit
integer, assign to J - End If
14Operators
- DESCRIPTION VB.NET Ex JAVA Ex
- String concatenation str1 str2 str3 str1
str2 str3 - str1 str2 str1 str2
- Addition int1 int2 int1 int2
- Add 1 n/a int1 int1 1 int1
- Comparison gt, lt gt, lt
- Equality If j 1 if (j 1)
- Inequality Not If Not j 1 ! if (j ! 1)
- ltgt If j ltgt 1
15Methods
VB.NET Function Function GetMe(ByVal s as
String) as String note the parameter s
s.Replace(h, hi) Return s End
Function Subroutine Sub SetMe(ByVal s as
String) Dim str1 as String s nothing to
return End Sub
Java Return Method String getMe(String
s) s s.replace(h, hi) return
s Void Method Void setMe(String
s) String str1 s
16Properties
VB.NET (1 property) Dim sCustomerName as String
Property CustomerName() As
String Get Return sCustomerName End
Get Set(ByVal Value As String) sCustomerName
Value End Set End Property
Java (2 accessor methods) String sCustomerName
String getCustomerName() return
sCustomerName void setCustomerName(String
name) sCustomerName name
17Loops
- Dim x as Integer 0
- Do While x lt 5
- x x 1
- Loop
Dim x as Integer 0 While x lt 5 x x 1 End
While
For j as Integer 0 to 10 Step
1 MsgBox(j) Next Dim MyArray() as Integer
1, 2, 3, 4, 6, 549 For Each i as Integer
in MyArray MsgBox(i) Next
18Exception Handling
- Syntax
- Try
-
- Catch var as Exception
-
- Finally
-
- End Try
- Example
- try converting a string to int32, then output
whether the conversion is successful - Dim MyInt as integer
- Dim bool as Boolean true
- Try
- MyInt Convert.ToInt32(Not Possible)
- Catch ex as Exception
- MsgBox(Error ex.Message)
- bool false
- Finally
- MsgBox(Conversion successful bool)
- End Try
19Database Access
- ADO.NET (ActiveX Data Objects)
- The .NET way to work with data
- Disconnected Architecture
- 2 Data Providers
- SQL Server specific provider for SQL Server
- Import System.Data.SqlClient
- OLEDB everything else, basically
- Import System.Data.OleDb
20ADO.NET
21Data Access Components
- Connection string
- http//www.able-consulting.com/ADO_Conn.htm
- Connection object
- SQL statement
- Command Object DataReader
- OR
- Data Adapter DataSet
22Connection String
- SQL Server Data Provider
- "Network LibraryDBMSSOCNData
Source111.11.111.111,3333 _ - Initial CatalogepicsUser IdepicsPasswordjd
s" - OLEDB Data Provider (SQL Server)
- "Providersqloledb" _
- "Data Source111.11.111.111,3333" _
- "Initial Catalogepics" _
- "User Idepics" _
- "Passwordjds"
- OLEDB Data Provider (Access)
- "ProviderMicrosoft.Jet.OLEDB.4.0Data
SourceT\www\mdb\WebInt.mdb"
23DataSet vs DataReader
- DataReader
- Object to access data in a connected,
forward-only, read-only fashion - DataSet
- Data structure to store schema and data in a
disconnected fashion - Useful for editing data offline and later update
to data source
24Database Connectivity
- Using SQL Server Data Provider and DataSet
- Dim strConn as String "Network
LibraryDBMSSOCNData Source111.11.111.111,3333
_ - Initial CatalogepicsUser IdepicsPasswordjd
s - Dim oConn as new SqlConnection(strConn)
- Dim strSQL as String select from
NODE_PROFILE - Dim oAdapter as new SqlDataAdapter(strSql,
oConn) - Dim ds as new DataSet
- oAdapter.Fill(ds, NODE_PROFILE)
- now we have a DataSet with data from the
NODE_PROFILE table - Using OLEDB Data Provider and DataReader
- Dim strConn as String "Providersqloledb"
"Data Source111.11.111.111,3333" _ - "Initial Catalogepics" "User
Idepics" "Passwordjds - Dim oConn as new OleDbConnection(strConn)
- Dim strSQL as string select from
NODE_PROFILE - Dim oCommand as New OleDbCommand(strSql, oConn)
- Dim oReader As OleDbDataReader
- oReader oCommand.ExecuteReader()
- now we have a DataReader with data from the
NODE_PROFILE table
25ADO.NET in JDS.2GO ??
- Not taking advantage of .NET data providers and
data structures - Using outdated technology objects from ADODB
class - This semester possibly transform all of JDS.2GO
to ADO.NET-standard
26ADO.NET
- Hands-on Exercise!!!!!!!!!!!
- Task build a simple VB.NET application with
database connectivity to display the front-end.
Based on existing C code