Unit-5-.net
Unit-5-.net
3
5.1 I N B U I L T F U N C T I O N S
There are there types of inbuilt function in
V B . N E T.
1) Mathematical Functions
2) String Manipulation Functions
3) Formatting Functions
4
1. M A T H E M A T I C A L FUNCTIONS
Example: Math.Abs(-8)
5
2) E x p function
❖ The Exp of a number x is the exponential value of x,
i.e. ex .
3) Fi x Function
❖ The Fix function truncate the decimal part of a positive
number and returns the largest integer but if
negative number give it returns smaller than the
number.
Syntax: Fix(Number) 6
Example: Fix(9.7)
4) Int Function
❖ The Int is a function that converts a number into an
integer by truncating its decimal part.
Syntax: Int(Number)
Example: Int(2.4
5) Log Function
❖ The Log function is the function that returns the natural
logarithm of a number.
Syntax: Math.Log (Number)
Example: Math.Log(10)
7
6) Rnd( ) Function
❖ The Rn d function returns a random value between
0 and 1.
Syntax: Rnd(Number)
Number is an optional argument
7) Round Function
The Round function is the function that rounds up a
number to a certain number of decimal places.
Syntax: Math.Round(Number)
9
5.2. S T R I N G M A N I P U L A T I O N F U N C T I O N S
1) Mid(string, start, [length]) Function
❖ The Mid() function returns a section of a string of
Example: Left(“Morning”,1)
4) Trim(“String”)Function
❖ The Ttrim function trims the empty spaces on both side
of the string .It remove empty space both side.
Syntax: Trim(“String”)
Syntax : Ltrim(“String”)
Example: Ltrim (“ Visual Basic.net”)
6) RTrim(“String”) Function
❖ The Rtrim function trims the remove empty spaces of
the right portion of the String.
Syntax: Rtrim(“String”)
Example: Rtrim (“ Visual Basic.net ”)
12
7) InStr Function
❖ This function searches one string into another string
and returns the starting position of the first
occurrence of a search string.
❖ Syntax: InStr([start,],string1,string2,[compare])
❖ Example: InStr(1,”Good Night”,
”Good”,CompareMethod.Text)
13
8) Ucase Function
❖ This function accepts a string or character as an
argument and returns a string or character converted
into upper case.
❖ Syntax : UCase(“String” or Character)
Example: UCase(“vpmp”)
9) Lcase Function
❖ This function accepts a string or character as an
argument and returns a string or character converted
into lowercase.
❖ Syntax : LCase(“String” or Character)
Example: LCase(“VPMP”)
14
9) C h r Function
❖ This function returns a character corresponds to the
A S C I I value specified as an argument.
❖ Syntax : Chr(char code)
❖ Example: Chr(65)
❖ Example: Asc(“A”)
15
3. F O R M A T T I N G FUNCTION
1. Now() Function
✓ This function returns both the system date and time.
The statement
Syntax:
MsgBox(Now())
displays a date/time combination such as
9/13/1998 09:23:10 P M in a message box. To extract the
date or time part of the value returned by the Now()
function, use the Date and TimeOfDay
properties:
Console.WriteLine(Now.Date.ToString)
Console.WriteLine(Now.TimeOfDay.ToString)
16
Formate Styles
Formate Style Description
General Date Format the Current Date & Time
Long Date or D Display the Current Date in long format
Short Date or d Display the Current Date in Short format
17
Example
Example Output
Format(Date.Now,”Gener 28/3/2017 3:10 P M
al Date”)
Format(Date.Now, “D”) Monday , March 28 2017
Format(Date.Now, “d”) 28/3/2017
18
5.3 A D O . N E T O B J E C T M O D E L
❖ A D O. N E T stands for Active X Data Object.
❖ A D O. N E T is an Object Oriented Set of Libraries
that allows to interact with Data Sources.& Data
Source is a Database.
❖ A D O. N E T provides data access services in the Microsoft
. N E T platform.
19
ADO.NET O B J E C T M O DEL /
ADO.NET ARCHITECTURE
20
ADO.NET O B J E C T MODEL
❖ You can use A D O. N E T to access data by using the new
. N E T Framework data providers which are:
21
ADO.NET O B J E C T M ODEL
❖ Architecture
of ADO.net basically consist of
two Components
1 ) . N E T Framework Data
Provider (connected objects)
2) DataSet
(disconnected Objects)
22
1.1 C O N N E C T I O N O B J E C T
❖ The Connection object Create the connection to the
database.
❖ The A D O Connection Object is used to create an open
connection to a data source. Through this connection,
you can access and manipulate a database.
❖ It is Two type of connection provide.
1. SqlConnection
2. OleDbConnection
1) Microsoft Access
Dim cn As New SqlConnection()
or 23
Connection String
❖ Connection string is a sequence of name and
value pair separated by semicolon.
❖ Connection string is used to specify name of provider,
type of data source , its location , username, password
24
etc.
EXAMPLE OF CONNECTION STRING
cn.ConnectionString=
"DataSource=.\SQLEXPRESS;AttachDbFilename
=C:\Users\-\documents\visual studio
2010\Projects\WindowsApplication1\Windows
Application1\Database1.mdf;Integrated
Security=True;User Instance=True"
25
PROPERTIES OF CONNECTION OBJECT
26
METHODS OF CONNECTION OBJECT
27
2. C O M M A N D OBJECT
❖ The A D O Command object is used specify query to
perform with data source or database.
28
❖ . Net Provides Two Type of Command
Classes:
1. SqlCommand
2. Oledb Command
29
COMMAND OBJECT
❖ Syntax to create Command Object
1) For Microsoft Access
Dim cmd As New OleDbCommand()
Or
Dim cmd As New OleDbCommand(Query, connection)
30
Example-1
Dim cn As New SqlConnection
("DataSource=.\SQLEXPRESS;AttachDbFilename=C:\Users\-
\documents\visual studio
2010\Projects\WindowsApplication1\WindowsApplication1\Database
1.mdf;Integrated Security=True;User Instance=True“)
31
3. D A T A R E A D E R
❖ DataReader provides a Read-only, Forward-only
stream of result from a database.
❖ Data reader object is used to retrieve records from data
source and examine them one by one.
❖ The important property of data reader are
1) Fast
2) Forward only
3) Read only
❖ Syntax
Dim dr As OleDbDataReader()
or
Dim dr As SqlDataReader()
33
4. D A T A A D A P T E R
❖ A DataAdapter (DataAdapter class) is an object used to
exchange data between a data source and a data set.
34
❖ Properties of DataAdapter
Properties Description
35
❖ Create Data Adapter Object
❖ Syntax
Dim adp As sqlDataAdapter()
❖ Create D a taAdapter object by passing
parameter
❖ Syntax
36
❖ Example-1
Dim cn As New SqlConnection(“Connection String”)
Dim q1 As String = “ select * from student;”
Dim cm As New SqlCommand(q1,cn)
Dim da As New SqlDataAdapter(cm)
37
D I F F E R E N C E S BETWEEN DATA ADAPTER &
DATA R E A D E R
D ata Reader D ataAdapter
Data Reader provides open & DataAdapter provides a
static forward–only connection. disconnected data
architechecture.
Single Row can be read at a Multiple Rows can be read at a
Time. Time.
Provides record in read-only Provides property to
mode. insert,update delete& retrieve
rows using commands.
Good choice for retrieving large Good choice for retrieving as
amount of data. well as to insert,update delete
data. 38
It works quickly It is not works quickly
2. D A T A S E T
❖ The DataSet is a Disconnected storage &
disconnected in Memory representation of Data.
40
D ATA S E T
41
PROPERTY O F DATASET
42
METHODS OF DATASET
43
DATA TABLE
45
DATA ROWS COLLECTION
❖ The DataRow and DataColumn objects are
primary components of a DataTable.
❖ Use the DataRow object and its properties and
46
DATA RELATION O B J E C T
➢ DataRelation object allows user to specify
relationship between different columns of different
DataTable objects.
➢ Relationship is useful to provide data integrity and
consistency. Relationship can be established
between two tables by defining a primary key in one
table and using a foreign key in the other table.
Create Data Relation object
Syntax:
Dim dr as new DataRelation(“Relation
Name”, ”ParentColumn”, ”ChildColumn”)
47
❖ 5.4 Bounded Gridview Step
❖ Step 1 : G o to Data Sources and click at "Add New Data
Source".
❖ Step 2 : A new window will be open.
❖ Step 3 : Click the Next button.
❖ Step 4 : Click the Next button.
❖ Step 5 : Click the "New connection" button to make a
new database connection.
48
❖ Step 6 : A new window will open asking to
save the connection string.
Step 7 : Click the Next button. In the new
window click the Table node to explore all
the tables of your database.
❖ Step 8 : Click the table node to explore all
columns. Then check the checkbox for each
column to select them. Look at the
following figure.
❖ Step 9 : Click the finish button.
49
IMP Q U E S T I O N
50