250 likes | 414 Vues
TOPICS. Visual Studio .NETVB.NET Code StructureVB.NET Language BasicsData Access in .NET. What is .NET ?. Microsoft
E N D
1. JDS VB.NET Skill Session Fall 2004
Presented by YUHAO LIN
2. TOPICS Visual Studio .NET
VB.NET Code Structure
VB.NET Language Basics
Data Access in .NET
3. What 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
4. What is VB.NET ? Visual Basic .NET
Next generation of Visual Basic
A programming language in the .NET framework
Fully object-oriented
5. Visual Studio .NET Available in Software Lab
Latest version: 2003
Integrated Development Environment (IDE) for developing .NET applications
6. Visual 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
7. Visual Studio .NET Code view
Comments
#Regions: collapse
Intellisense
Run / compile
Debug / step into
Executable file
Location: bin or obj subdirectory
8. VB.NET Code Structure VB.NET
Import statements
Namespace
Class
Functions / Subs
Properties
Class variables
9. VB.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
10. VB.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
11. Programming Review Car myCar = new Car(Ford, Escort)
What did I do ??
12. Common Data Types Integer
Double
Boolean
String
Array
13. Data 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
14. Operators 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 >=, <= >=, <=
Equality = If j = 1 == if (j == 1)
Inequality Not If Not j = 1 ! if (j != 1)
<> If j <> 1
15. Methods
16. Properties
17. Loops Dim x as Integer = 0
Do While x < 5
x = x + 1
Loop
18. Exception Handling Syntax:
Try
Catch var as Exception
Finally
End Try
19. Database 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
20. ADO.NET
21. Data Access Components Connection string
http://www.able-consulting.com/ADO_Conn.htm
Connection object
SQL statement
Command Object & DataReader
OR
Data Adapter & DataSet
22. Connection String SQL Server Data Provider:
"Network Library=DBMSSOCN;Data Source=111.11.111.111,3333; & _
Initial Catalog=epics;User Id=epics;Password=jds"
OLEDB Data Provider (SQL Server):
"Provider=sqloledb;" & _
"Data Source=111.11.111.111,3333;" & _
"Initial Catalog=epics;" & _
"User Id=epics;" & _
"Password=jds"
OLEDB Data Provider (Access):
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=T:\www\mdb\WebInt.mdb"
23. DataSet 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
24. Database Connectivity Using SQL Server Data Provider and DataSet:
Dim strConn as String = "Network Library=DBMSSOCN;Data Source=111.11.111.111,3333; & _
Initial Catalog=epics;User Id=epics;Password=jds
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 = "Provider=sqloledb;" & "Data Source=111.11.111.111,3333;" & _
"Initial Catalog=epics;" & "User Id=epics;" & "Password=jds
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
25. ADO.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
26. ADO.NET Hands-on Exercise!!!!!!!!!!!
Task: build a simple VB.NET application with database connectivity to display the front-end. Based on existing C# code