Presentation is loading. Please wait.

Presentation is loading. Please wait.

JDS – VB.NET Skill Session Fall 2004 Presented by YUHAO LIN.

Similar presentations


Presentation on theme: "JDS – VB.NET Skill Session Fall 2004 Presented by YUHAO LIN."— Presentation transcript:

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 Microsoft’s 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 Java Package Import statements –Class Methods Accessor methods 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 Java package com.deitel.chp08; import java.io.*; public class Driver { void newRecord() { … } String getRecord() { … return strX; }

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 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

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 DESCRIPTIONVB.NETEx JAVAEx String concatenation&str1 = str2 & str3+str1 = str2 + str3 &=str1 &= str2+=str1 += str2 Addition+=int1 += int2+=int1 += int2 Add 1n/aint1 = int1 + 1++int1++ Comparison>=, =, <= Equality=If j = 1==if (j == 1) InequalityNotIf Not j = 1!if (j != 1) <>If j <> 1

15 Methods 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; }

16 Properties 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; }

17 Loops Dim x as Integer = 0 Do While x < 5 x = x + 1 Loop Dim x as Integer = 0 While x < 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

18 Exception 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

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.htmhttp://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


Download ppt "JDS – VB.NET Skill Session Fall 2004 Presented by YUHAO LIN."

Similar presentations


Ads by Google