NET All Units
NET All Units
NET Framework
Page 1
Unit 1. Overview of Microsoft .NET Framework
Page 2
Unit 1. Overview of Microsoft .NET Framework
Execution In CLR
Page 3
Unit 1. Overview of Microsoft .NET Framework
Page 4
Unit 1. Overview of Microsoft .NET Framework
It is a set of rules and constraints that all language must follow which want to be
compatible with .NET framework.
It is used to support the theme of .NET i.e. unification and interoperability (The ability
of computer systems or software to exchange and make use of information). That
means, if we want the code which we write in a language to be used by programs in
other language(cross-language integration) then it should hold on to the CLS.
Thus the CLS describes a set of features that are common different languages.
CLS performs the following functions:
Page 5
Unit 1. Overview of Microsoft .NET Framework
Assembly All of the managed code that runs in .NET must be contained in an assembly.
Logically, the assembly is referenced as one EXE or DLL file. Physically, it may consist of a
collection of one or more files that contain code or resources such as images or XML data. An
assembly is created when a .NET compatible compiler converts a file containing source code
into a DLL or EXE file.
Manifest. Each assembly must have one file that contains a manifest. The manifest is a set of
tables containing metadata that lists the names of all files in the assembly, references to
external assemblies, and information such as name and version that identify the assembly.
Metadata When a compiler produces Microsoft Intermediate Language (MSIL), it also produces
Metadata (Data about Data). Metadata is nothing but a description of every namespace, class,
method, Property etc. The Microsoft Intermediate Language (MSIL) and Metadata are
contained in a portable executable (PE) file. It allows loading and locating code, enforcing code
security, generating native code, and providing reflection at runtime.
Page 6
Unit 1. Overview of Microsoft .NET Framework
Execution in CLR
When the .NET program is compiled, the output of the compiler is not an executable file but a
file that constraints a special type of code is called Microsoft intermediate language , which is a
low level set of instructions understand by CLR.
The MSIL defines a set of portable instructions that are CPU indendendent.
It’s the job of the CLR to translate this MSIL into native code when the program is
executed, making the program to run in any environment for which the CLR is
implemented. And that’s how the .NET framework achieves Portability (run in any
environment). This MSIL is converts into Native code using JIT(Just In Time)compiler
Purpose of CLR
Page 7
Unit 1. Overview of Microsoft .NET Framework
Thread Support: Threads are managed under the Common Language Runtime.
Threading means parallel code execution. Threads are basically light weight processes
responsible for multi-tasking within a single application.
COM Marshaler: It allows the communication between the application and COM
objects.
Type Checker Type checker will verify types used in the application with CTS or CLS
standards supported by CLR, this provides type safety.
Exception Manager: it handles all the runtime exceptions(Error) thrown by application
Security Engine: It enforces security permissions at code level security, folder level
security, and machine level security using Dot Net Framework setting and tools
provided by Dot Net.
Debug Engine: CLR allows us to perform debugging an application during runtime.
MSIL: Microsoft Intermediate Language is considered to be the lowest form of human
readable language. It is CPU independent and includes instructions of how to load,
store, initialize objects. JIT converts this MSIL into native code which is independent on
the CPU
Code Manager: CLR manages code. When we compile a .NET application you don't
generate code that can actually execute on your machine. You actually generate
Microsoft Intermediate Language (MSIL or IL). All .NET code is IL code. IL code is also
called Managed Code, because the .NET Common Language Runtime manages it.
Garbage Collector Garbage Collector handles automatic memory management and it
will release memory of unused objects in an application, this provides automatic
memory management.
Class Loader: as and when needed. It loads the class into the system memory.
Page 8
Unit 1. Overview of Microsoft .NET Framework
Namespace is the Logical group of types (Class). We can say Namespace is a container (e.g.
Class, Structures, Interfaces, and Enumerations etc).
System.Data.SqlClient
System.Data.OleDb
System.Data.Odbc
System.IO Provides file and data stream I/O. These classes provide a way to access
the underlying file systems of the host operating system.
System.Windows.Forms Classes used to build Windows desktop GUI applications. Controls
including the ListBox, TextBox, DataGrid, and buttons are found here.
System.Xml Types for processing XML.
System.Web The Internet-related classes referred to as ASP.NET. They manage
browser-server communication requirements, manipulate cookies, and
contain the controls that adorn a Web page.
System.Web.Services Web.Services includes those classes required for SOAP-based XML
messaging.
Page 9
Unit 1. Overview of Microsoft .NET Framework
It defines how types are declared, used, and managed in the common language runtime, and is
also an important part of the runtime's support for cross-language integration.
The common type system performs the following functions:
Establishes a framework that helps enable cross-language integration, type safety, and
high-performance code execution.
Provides an object-oriented model that supports the complete implementation of many
programming languages.
Defines rules that languages must follow, which helps ensure that objects written in
different languages can interact with each other.
Provides a library that contains the primitive data types (such
as Boolean, Byte, Char, Int32, and UInt64) used in application development.
For example, C# has an int data type and VB.NET has Integer data type. Hence a variable
declared as an int in C# and Integer in VB.NET, finally after compilation, uses the same
structure Int32 from CTS.
Page 10
Unit 1. Overview of Microsoft .NET Framework
Page 11
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Sascma BCA College
Unit 4.Object Oriented Programming
Class
• Class is a group of methods and variables where methods are known as Member function and variables
are known as Data Member.
• In vb.net class is created using Class Keyword and completed with End Class.
• Once class is created you can created any number of objects.
Syntax
[<attrlist>][Access Modifier]
[Shadows][MustInherit|NotInheritable]Class<classname>
[statement(s)]
o Access_Specifier: It defines the access levels of the class, like Public, Private or Friend,
Protected, Protected Friend, etc. to use the method. (It is an optional parameter).
o Shadows: It is an optional parameter. It represents the re-declaration of variables and hides an
identical element name or set of overloaded elements in a base class.
o MustInherit: It is an optional parameter that specifies that the class can only be used as a base
class, and the object will not directly access the base class or the abstract class.
o NotInheritable: It is also an optional parameter that representing the class not being used as a
base class.
o Partial: As the name defines, a Partial represents the partial definition of the class (optional). o
Implements: It is used to specify interfaces from which the class inherits (optional). Example
Objects
Syntax
<object> As New <Class Name>
Example
Abstraction
• It refers to the act of representing essentials features without including the background details or
explanations.
• It defines way to abstract or hide your data and members from outside class.
• Classes use the concept of Abstraction.
• When we define a classes then different accessibility mode define the access level of variables and
methods. They are Public, Private, Protected.
Example
• It is a process to bind data and methods in a unit called class. When we define class that process itself
define the concept of Encapsulation.
• When we define class that process itself define the concept of Encapsulation.
• It can protect your data from accidental corruption.
• Rather than defining the data in the form of public, we can declare those fields as private.
Example:
End Sub
Sub display()
MsgBox("Subject code:" & scode & " " & "Subject Name:" & sname)
End Sub
End Class
Constructor
• A constructor is a special procedures which are called automatically when object of the class is created
to initialize the object.New keyward is used to create constructor.Constructor can be overloaded.
Example:
Add class file and give name constructorexample
End Class
• How to call Base Class Constructor o It can be called using
MyBase keyword. o It cannot be used to access private members
of class. o It refers to the immediate base class and its inherited
members .
Example:
Public Class ClsBase
Private x, y As Integer
Sub New() x = 0
y = 0
End Sub
Sub New(ByVal a As Integer, ByVal b As Integer)
x = y y = b
End Sub
End Class
End Sub
End Class
Add windows form and write down the following code in btnconstructor click event.
Public Class Form1
Destructor(Finalize)
• Destructor is a special function which is called automatically when a class is destroyed.It is a last method
run by a class.
• It is called when ever the .NET runtime is told directly or otherwise determines that an object is no
longer required.
• Within a destructor we can place code to clean up the object after it is used ,which might include
decrement counters releasing resources.
• It cannot be overloaded.
Syntax
Logic
End Sub
Example:
Inheritance
o It is a process of creating a new class called derives class from the existing class called Base Class. o The
existing class is known as parent, base, super class.
• The new class is known as child, derive, sub class.
• It is also known as code reusability.
• It can be created by using inherits keyword.
• A derive class obtain all of the methods, properties, and events of the base class.
o Inherits
o NotInheritable o MustInherit(Abstract Class)
Syntax
Syntax
Class<class Name>
End Class
Polymorphism
Example:
End Function
Example:
End Sub
End Class
Public Class clsderived
Inherits base
Public Overrides Sub dis()
MyBase.dis()
MsgBox("Derived class")
End Sub
End Class
End Class
• Interface
We cannot inherit more than one class in vb.net. If we wants to inherit then? Use interface
Interface
• Interfaces like classes define a set of properties, methods and events. But unlike classes, an interface does
not contain any implementation code
• Interface represents “Has a” relationship
• Classes which implements interface they write the coding in the interface’s method
• We can implements multiple interface
• If we want to use interface then we need to write” Implements” keyword Syntax Public Interface iface1
….logic End Interface
Syntax
Public interface abc1
….logic
End interface
End Sub
End Class
i. Database Diagram
Database diagram tool allows user to design and visualize a database to
which we are connected. This diagram contains the tables along with the
relationship and primary key.
ii. Table designer
It provides an entire window to design the individual table. It also allow
user to change an existing database by changing, adding, duplicating and
deleting table. It is used to add or remove columns, specify its data type,
size, description, keys, constraints and relationships.
Page 1
Unit 5 Database access using ADO.NET
ADO.NET
o ADO.NET has the ability to separate data access mechanisms,data
manipulation mechanisms and data connectivity mechanisms.
o ADO.NET ia a set of classes that allow application to read and write
information in database.
o ADO.NET can be used by any .NET language.
o We need to add System.Data namespace for work with ADO.NET.
o Ado.Net is a technology which works between access database
Frontend Application. It is used to access database.
The Data Provider is responsible for providing and maintaining the connection
to the database.
Page 2
Unit 5 Database access using ADO.NET
A connection object establishes the connection for the application with the
database.
The command object provides direct execution of the command to the database.
If the command returns more than a single value, the command object returns a
DataReader to provide the data.
Page 3
Unit 5 Database access using ADO.NET
Data Providers:
Page 4
Unit 5 Database access using ADO.NET
o Ado.NET Objects
ADO.NET consists of many objects that are used to work with data.
a) Connection Object
b) Command Object
c) DataAdapter Object
d) DataReader Object
a) Connection Object
To establish connection with a database,you must have a connection
object.
The connection object helps to identify the datadase sever,the
database name,user name,password,and other parameters that are
required for connecting to the database.
A connection object is used by command objects so that it will know
on which database the command is executed.
con.ConnectionString = "Data
Source=.\SQLEXPRESS;AttachDbFilename=D:\jigisha\vb.netDemo_s
y6\sy6\sy6\Database1.mdf;Integrated Security=True;User
Instance=True"
Properties
Properties Description
conectionString It stores the connection string that is passed to the
connection object at the time of creating its object.
Database It stores the name of the database to which you need to
connect.
State It return the state of thae connectionEX.IsClose or IsOpen
Page 5
Unit 5 Database access using ADO.NET
Connection TimeOut Gets the time to wait while trying to establish a connection
before terminating the attempt and generating an error.
Methods
Methods Description
Open It opens the connection
Close It closes the connection
BeginTransaction It creates the Transaction Object.
ChangeDatabase It creates and returns a SqlCommand object associated with
the SqlConnection.
ChangeDatabase It changes the current database for an open SqlConnection.
Properties
Properties Description
Connection To set a connection object.
CommandText It specifies the SQL string or stored procedure to be
executed.
CommandType It is used to determine how to interpret command text.
Ex. CommandText is storedprocedure or Text or DirectTable.
CommandTimeOut Gets the time to wait while trying to execute the command
before terminating the attempt and generating an error.
Methods
Methods Description
ExecuteNonQuery It will execute the SQL statement and returns the number
of rows affected by the query.
ExecuteScalar It will execute the SQL statement which return the
Page 6
Unit 5 Database access using ADO.NET
singleton value.
ExecuteReader It will execute the SQL statement and returns the records
in the form of DataReader.Ex.it is used to create the object
of DataReader.
CreateParameter It creates and returns a Sqlparameter object associated
with the SqlCommand.
Cancel It is used to cancel the command given for for execution.
ResetCommandTimeOut It is used to reset Command time out property to its
default value.
( C ) DataReader Object
Properties
Properties Description
FieldCount It stroes number of fields in a row.
HasRows It specifies that the rows are selected or not for reading.
IsClosed It specifies that DataReader is closed or not.
RecordsAffected It returns -1 as DataReader is created on server.
Item It gets the value of the specified column name.
Methods
Methods Description
Read It reads the Next Record of DataReader.
Close It is used to Close the DataReader Connection with the
database.
IsDBNull It checks that the value of the column is Null or net.
GetSchemaTable It returns the object of the DataTable for which the
DataReader is created.
GetValues It returns the array of the values for the row.
NextResult It is used to nagate from one record set to another when
Page 7
Unit 5 Database access using ADO.NET
(e) DataAdapter
It acts as a bridge between data source and in-memory data objects such as
the Dataset.
Properties
Properties Description
selectCommand It is used to hold a Command that retrieves data from the
data source.
UpdateCommand It is used to hold a Command that updates data from the
data source.
DeleteCommand It is used to hold a Command that delete data from the data
source
InsertCommand It is used to hold a Command that insert data from the data
source
Command and Type It indicates CommandText property which contains SQL
statement or stored procedure.If commandText property
contains stroed procedure than user can set the value to
CommandType.stored procedure.Default value is
CommandType.Text for SQL statement.
Methods
Methods Description
Fill It is used to populate a dataset object with the data that the
DataAdapter object retrieve from the data store using its
SelectCommand.But before that we must initialize a Dataset
object.
Update It is used to update the database according to the changes
that are made in the DataSet.
(2) DataSet
Page 8
Unit 5 Database access using ADO.NET
con.ConnectionString = "Data
Source=.\SQLEXPRESS;AttachDbFilename=D:\jigisha\vb.net
Demo_Example\Demo_Example\Demo_Example\Database1.mdf;Integrated Security=True;User
Instance=True"
cmd.Connection = con
Catch ex As Exception
MsgBox(ex.Message)
End Try
display()
End Sub
Sub display()
Try
cmd.CommandText = "select * from Employee"
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
DataGridView1.DataSource = dt
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Page 9
Unit 5 Database access using ADO.NET
cmd.CommandText = "insert into Employee values('" & txtid.Text & "','" &
txtname.Text & "'," & txtsalary.Text & " )"
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Record is inserted")
Catch ex As Exception
MsgBox(ex.Message)
End Try
display()
clearconrtol()
End Sub
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Sub
Page 10
Unit 5 Database access using ADO.NET
End Sub
Sub clearconrtol()
txtname.Text = ""
txtid.Text = ""
txtsalary.Text = ""
End Sub
End Class
Output:
Output:
Page 11
Unit 5 Database access using ADO.NET
Page 12