.net project lalatendu

67
INTRODUCTION TO .NET FRAMEWORK Microsoft’s new software development platform, .NET Framework, is the first Microsoft development environment designed from the ground up for Internet development. Although .NET is not meant to be used exclusively for Internet development, its innovations were driven by the limitations of current Internet development tools and technology. The basis of this new development platform consists of three primary components or layers: the common language runtime, the .NET Framework base classes, and the user and program interfaces. .NET is the Microsoft Web services strategy to connect information, people, systems, and devices through software. Integrated across the Microsoft platform, .NET technology provides the ability to quickly build, deploy, manage, and use connected, security-enhanced solutions with Web services. .NET-connected solutions enable businesses to integrate their systems more rapidly and in a more agile manner and help them realize the promise of information anytime, anywhere, on any device. We can reveal Visual Basic .NET (VB.NET) as an object-oriented computer language that can be viewed as an spiritual evolution of Microsoft's Visual Basic (VB) implemented on the Microsoft .NET framework. .NET framework is an essential component of the windows operating system which helps in creating applications by integrating different programming languages such as C#, C++, JSP, and Visual C++. This framework consists of a virtual execution system called as Common Language Runtime (CLR) and a set of class library. The .NET framework is used to integrate the business logic of an application, implemented in various programming languages and services. Consequently it reduces significant improvement in code reusability, specialization, resource management, development of application in multiprogramming languages, security, deployment and administration of programs developed in multiple programming languages. ARCHITECTURE OF .NET FRAMEWORK .NET framework consists of the common language runtime,.net framework class library, windows form, asp.net form, console application, activex data object, .net framework class library, common language specification , common type system and .net languages such as c#, VB, VC++. Fine9™

Upload: lalatendu

Post on 27-Oct-2014

26 views

Category:

Documents


1 download

DESCRIPTION

This is .Net projects for IT Students.

TRANSCRIPT

Page 1:  .Net Project Lalatendu

INTRODUCTION TO .NET FRAMEWORK

Microsoft’s new software development platform, .NET Framework, is the first Microsoft

development environment designed from the ground up for Internet development. Although

.NET is not meant to be used exclusively for Internet development, its innovations were driven

by the limitations of current Internet development tools and technology. The basis of this new

development platform consists of three primary components or layers: the common language

runtime, the .NET Framework base classes, and the user and program interfaces.

.NET is the Microsoft Web services strategy to connect information, people, systems, and

devices through software. Integrated across the Microsoft platform, .NET technology provides

the ability to quickly build, deploy, manage, and use connected, security-enhanced solutions

with Web services. .NET-connected solutions enable businesses to integrate their systems

more rapidly and in a more agile manner and help them realize the promise of information

anytime, anywhere, on any device.

We can reveal Visual Basic .NET (VB.NET) as an object-oriented computer language that can

be viewed as an spiritual evolution of Microsoft's Visual Basic (VB) implemented on the

Microsoft .NET framework.

.NET framework is an essential component of the windows operating system which helps in

creating applications by integrating different programming languages such as C#, C++, JSP,

and Visual C++.

This framework consists of a virtual execution system called as Common Language

Runtime (CLR) and a set of class library.

The .NET framework is used to integrate the business logic of an application,

implemented in various programming languages and services. Consequently it reduces

significant improvement in code reusability, specialization, resource management,

development of application in multiprogramming languages, security, deployment and

administration of programs developed in multiple programming languages.

ARCHITECTURE OF .NET FRAMEWORK

.NET framework consists of the common language runtime,.net framework class

library, windows form, asp.net form, console application, activex data object, .net framework

class library, common language specification , common type system and .net languages such as

c#, VB, VC++.

Fine9™

Page 2:  .Net Project Lalatendu

EVOLUTION OF .NET

Microsoft released its first version of .net with the name of .net framework 1.0 on 13th February

2002, along with the visual studio .net 2002 integrated development environment (IDE). The

second revised version of .net framework 1.1 took nearly a year to release. Microsoft visual

studio.net better known as visual studio. .Net 2003 was also a part of second release. The next

version of .net framework 2.0 was released with visual studio .net 2005 on 7th November 2005.

INTRODUCTION TO VISUAL BASIC .NET

Visual Basic is a programming language based on the original DOS language called BASIC.

VB .NET 2005, an offshoot of visual basic, is an object oriented programming language based

on VB that is implemented using the Microsoft .NET framework. The syntax of visual basic

language remains unchanged in VB.NET 2005, but includes additional features such as

structured exception handling and short circuited expressions to enhance the infrastructure of

the programming language.

Visual Basic .NET is a programming language that can be used to create windows forms or web

applications and create programming based in any object oriented programming

language(OOP),ADO.NET ,multithreading or windows services.

VB.NET programming utilizes concepts connected to string encryptions, forms inheritance,

regular expressions and deployment.

COMMON LANGUAGE RUNTIME(CLR):-

It is a compiler for whole .NET framework. It takes over application which is written in

.NET converts it into it’s the native processor or Microsoft Intermediate language(MSIL) code

or machine understandable code and finally runs it. i.e CLR is the interface between

application & Operating System. The CLR manages the execution of the code , hence the code

that works on CLR is called the manage code.

Fine9™

Page 3:  .Net Project Lalatendu

Components of .NET Framework

VB.NET IDE:-

The Vb.net IDE is consisting of a no of components these are: menu bar, toolbar,

project explorer, properties window, form layout window, toolbox, form designer & object

browser.

Fine9™

Page 4:  .Net Project Lalatendu

THE TOOLBARS:-

A tool bar contains a set of controls that are used to place on a form at design time. There by

creating the user interface area. Additional controls can be included in the toolbox by using the

component menu item on the project menu. A toolbox is presented on fig below. The toolbar

give you quick access to commonly used menu commands. Besides the main toolbar, the visual

basic IDE provides additional toolbar for specific purposes, such as editing, form design &

debugging.

The standard toolbar is just below the menu bar & is displayed by default.

The edit toolbar contains the command for the edit menu.

The debug toolbar contains the command of the debug menu.

The form editor toolbar contains the command of the format menu.

THE PROJECT EXPLORER:-

The window titled project is the project explorer, which displays the components of

the project. The project components are organized in folder, & the project window is called

explorer. Visual basic 6 can manage projects & group of projects.

THE PROPERTIES WINDOWS:-

The property window contains the property setting for the selected control.

Properties are attributes of an object, such as its size; caption & color .you can adjust the

appearance of the control on the form with point & click operation.

THE TOOLBOX:-

The toolbox contains the icons of the controls you can place on a form to create the

applications basic IDE & their names are shown as follows.

Picture box is used to display images, & the images are set with the picture property.

The picture box control supports a number of methods for generating drawing.

Label displays text on a form that the user cannot edit. Labels commonly identify other

controls on the form.

Textbox displays text that the user can edit. The textbox control is a mini text editor, &

its most important property, is the text property, which can set the text on the control or

read the text that the user enters.

Fine9™

Page 5:  .Net Project Lalatendu

Command button- is the most common element of the windows interface .a command

button represents an action that is carried out when the users click the button.

Check box- presents one or more choices that the user can select. The check box

control’s main property is value, & it is 0 if the check box is cleared & 1 if the check box

is checked .the check box is a toggle. Every time it is clicked, it changes status.

Option button- or radio buttons appear in groups & the user can chose only one of

them. The option button main property is checked, & it is true if the control is checked

& false otherwise. It is a toggle. Every time it is clicked, it changes status.

Combo box- is similar to the list box control, but it contains a text edit field. The user

can either choose an item from a list or enter a new string in the edit field. The item

selected from the list is given by the control’s text property.

List box- contains a list of option from which the user can choose one or more. It can

contain property of the list box determines whether the items in the list will be sorted.

The horizontal & vertical scroll bar- let the user specify a magnitude by scrolling the

controls button between its minimum & maximum value.

Timer perform task at regular interval, which determines how often the timer notifies

your application.

A FEW COMMON PROPERTIES:-

The following properties apply to most objects.

Name sets the name of the control, through which you can access the controls

properties & methods.

Appearance can be 0 for a flat look & 1 for a 3-D look.

Back color sets the background color on which text is displayed or graphics are drawn.

Fore color sets the fore ground color.

Fine9™

Page 6:  .Net Project Lalatendu

Font sets the face, attribute & size of the font used for the text on the control.

Caption sets the text that is displayed on many controls that don’t accept input.

Text sets the text that is displayed on the control that accepts users input.

Width, Height sets the controls dimension usually the dimension of a control is

determined with the visual tools. But you can read the controls dimension or set them

from within your code with these properties.

Left, Top sets the co-ordinate of the control upper left corner, expressed in the unit of

the the form lay out window, but you can change it from within your code with these

two properties.

Enabled value is true, which means that the control can get the focus. Set it to false to

disable control. A disabled control appears gray & cannot accept user’s input.

Visible- set this property to false to make a control invisible. Sometimes you use

invisible & should not be seen or manipulated by the user.

DECLARATION OF VARIABLE VB.NET:-

We often need to store values temporarily when performing calculation with visual variable for

storing values. Variables have a name & a data type.

In case of VB.net we declare a variable using DIM statement (DIM=Dimension)

DIM <variable name>as <data type>

DIM result as integer

DATATYPES IN VB.NET:-

Variables have a name & a data type. The data types of a variable determine how the

bits & bytes representing those values are stored on computer memorial variables have a data

type that determines what kind of data they can store. The Data types available in VB

.NET, their size, type, description are summarized in the table below.

Fine9™

Page 7:  .Net Project Lalatendu

Data Type Size in Bytes Description Type

Byte 1 8-bit unsigned

integer System.Byte

Char 2 16-bit Unicode

characters System.Char

Integer 4 32-bit signed integer System.Int32

Double 8 64-bit floating point

variable System.Double

Long 8 64-bit signed integer System.Int64

Short 2 16-bit signed integer System.Int16

Single 4 32-bit floating point

variable System.Single

String Varies Non-Numeric Type System.String

Date 8 System.Date

Boolean 2 Non-Numeric Type System.Boolean

Object 4 Non-Numeric Type System.Object

Decimal 16 128-bit floating

point variable System.Decimal

OPERATORS IN VB.NET:-

with many built-in operators that allow us to manipulate data.

An ope

rithmetic Operators

Visual Basic .net comes

rator performs a function on one or more operands. There are different types of

operators in Visual Basic and they are described below in the order of their precedence.

A

Fine9™

Page 8:  .Net Project Lalatendu

Arithmetic operators are used to perform arithmetic operations that involve calculation

of numeric values. The table below summarizes them:

Operator Use

^ Exponentiation

Negation (used to reverse the sign of the given

value, exp -intValue) -

* Multiplication

/ Division

\ Integer Division

Mod Modulus Arithmetic

+ Addition

- Subtraction

Concatenation Operators

in multiple strings into a single string. There are two concatenation Concatenation operators jo

operators, + and & as summarized below:

Operator Use

+ String Concatenation

& String Concatenation

Comparison Operators

Fine9™

Page 9:  .Net Project Lalatendu

A comparison operator compares operands and returns a logical value based on whether the

comparison is true or not. The table below summarizes them:

Operator Use

= Equality

<> Inequality

< Less than

> Greater than

>= Greater than or equal to

<= Less than or equal to

Logical / Bitwise Operators

The logical operators compare Boolean expressions and return a Boolean result. In short,

logical operators are expressions which return a true or false result over a conditional

expression. The table below summarizes them:

Operator Use

Not Negation

And Conjunction

Or Disjunction

PROGRAMMING CONSTRUCT

Fine9™

Page 10:  .Net Project Lalatendu

There are basically two types of control statements.

1.Decision-statements are of four types

….endif

ndif

2. Looping- statements are of three types

.end while

ext

Sub Pocedure

Decision construct

Looping construct

If…

If….Else…..e

Nested if

Select case

While…

Do….loop

For…..next

For each….n

:-

Sub procedures are methods which do not return a value. Each time when the Sub procedure is

s

Function

called the statements within it are executed until the matching End Sub is encountered. Sub

Main(), the starting point of the program itself is a sub procedure. When the application start

execution, control is transferred to Main Sub procedure automatically which is called by

default.

:-

nction is similar to a subroutine, but a function returns a result. Subroutines

ry out

nd

unction NextDay() As Date

teInterval.Day, 1, Now())

A fu

perform a task and don’t report anything to the calling program; functions commonly car

calculations and report the result. Because they return values, functions—like variables—have

types. The value you pass back to the calling program from a function is called the return value,

and its type must match the type of the function. Functions accept arguments, just like

subroutines. The statements that make up a function are placed in a set of Function…E

Function statements, as shown here:

F

Dim theNextDay As Date

theNextDay = DateAdd(Da

Return(theNextDay)

Fine9™

Page 11:  .Net Project Lalatendu

End Function

PROGRAMS:-

/write program for printing a message.

ublic Class Form2

ck(ByVal sender As System.Object, ByVal e As

System

rk"

ate Sub Button2_Click(ByVal sender As System.Object, ByVal e As

System

ate Sub Button3_Click(ByVal sender As System.Object, ByVal e As

System

UTPUT

/

P

Private Sub Button1_Cli

.EventArgs) Handles Button1.Click

Label1.Text() = "Welcome to .NET Framewo

End Sub

Priv

.EventArgs) Handles Button2.Click

Label1.Text() = " "

End Sub

Priv

.EventArgs) Handles Button3.Click

Me.Close()

End Sub

End Class

O :

/Addition of two number

/

Fine9™

Page 12:  .Net Project Lalatendu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

r, num2 As Integer, result As Integer

num2

End Sub

ate Sub Button2_Click(ByVal sender As System.Object, ByVal e As

System

ub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

UTPUT

Handles Button1.Click

Dim num1 As Intege

num1 = TextBox1.Text

num2 = TextBox2.Text

TextBox3.Text = num1 +

Priv

.EventArgs) Handles Button2.Click

TextBox1.Text = " "

TextBox2.Text = " "

TextBox3.Text = " "

End Sub

Private S

Handles Button3.Click

End

End Sub

End Class

O :-

Fine9™

Page 13:  .Net Project Lalatendu

//Changing color using textbox

ublic Class Form1

heckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e

As Syst

ate Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e

As Syst

CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As

ate Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System

End Sub

UTPUT

P

Private Sub C

em.EventArgs) Handles CheckBox1.CheckedChanged

BackColor() = Color.Red

End Sub

Priv

em.EventArgs) Handles CheckBox2.CheckedChanged

BackColor() = Color.Blue

End Sub

Private Sub

System.EventArgs) Handles CheckBox3.CheckedChanged

BackColor() = Color.Yellow

End Sub

Priv

.EventArgs) Handles Button1.Click

Me.Close()

End Class

O :-

Fine9™

Page 14:  .Net Project Lalatendu

//changing color using button

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click

Me.BackColor() = Color.Black

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button2.Click

Me.BackColor() = Color.Blue

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As

ystem.EventArgs) Handles Button3.Click

End Sub

utton4_Click(ByVal sender As System.Object, ByVal e As

System

S

Me.BackColor() = Color.Yellow

Private Sub B

.EventArgs) Handles Button4.Click

Me.BackColor() = Color.Green

End Sub

End Class

OUTPUT:-

Fine9™

Page 15:  .Net Project Lalatendu

//Addition of two number using function

Public Class Form1

Dim a, b, c, x As Integer

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click

a = TextBox1.Text

b = TextBox2.Text

c = add(a, b)

TextBox3.Text = c

End Sub

Function add(ByVal i As Integer, ByVal j As Integer)

x = i + j

Return x

nd Class

End Function

E

OUTPUT:-

//program using procedure

Public Class Form1

Inherits System.Windows.Forms.Form

Dim ename As String

Dim sal As Single

Fine9™

Page 16:  .Net Project Lalatendu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button1.Click

If TextBox1.Text <> " " And Val(TextBox2.Text) <> 0 Then

ename = TextBox1.Text

sal = TextBox2.Text

Call post1(ename)

Call post1(sal)

Else

MsgBox("Please enter valid data in the text boxes")

End Sub

ame As String)

name

Public Overloads Sub post1(ByVal sal1 As Single)

UTPUT

End If

Public Overloads Sub post1(ByValempn

Label3.Text = emp

End Sub

Label4.Text = sal

End Sub

End Class

O :-

//program for calling a form and displayingthe data

Fine9™

Page 17:  .Net Project Lalatendu

Public Class Form1

Inherits System.Windows.Forms.Form

Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

on1.Click

Dim f2 As New Form2()

f2.Show()

f2.Label1.Text = TextBox1.Text

f2.Label2.Text = TextBox2.Text

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles TextBox1.Leave

If Asc(TextBox1.Text) >= 97 And Asc(TextBox1.Text) <= 123 Then

MsgBox("Correct val ")

Else

MsgBox("InCorrectvalRe enter ")

TextBox1.ForeColor = Color.Red

Private Sub

Handles Butt

TextBox1.Focus()

End If

End Sub

End Class

OUTPUT:-

Fine9™

Page 18:  .Net Project Lalatendu

//Create an Application for LOGIN VALIDATION

orm1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button1.Click

If

TextBox1.Text = "RAVENSHAW" And

TextBox2.Text = "RAVENSHAW" Then

form2.show()

Else

Label4.text = "invalid entry"

End If

End Sub

End Class

Public Class F

OUTPUT:-

(Here user name & password is same)

Fine9™

Page 19:  .Net Project Lalatendu

(Here user name & password is not same)

orking with Progress Bar Control in VB.Net

W

In this article you will learn how to work with Progress Bar Control and Mouse Wheel event of

the window form.

Create a New Project in VB.net. Drag a Progress bar control from tool box and place on form

and now drag and drop four buttons on form having text l< << >> >l. this is simple interface for

this purpose.

Now write code on form load even of the form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles MyBase.Load

ProgressBar1.Minimum = 0

ProgressBar1.Maximum = 100

ProgressBar1.Value = 0

End Sub

Now write code on button click events.

Fine9™

Page 20:  .Net Project Lalatendu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button1.Click

If ProgressBar1.Value < 100 Then

ProgressBar1.Value += 5

End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button2.Click

If ProgressBar1.Value > 0 Then

ProgressBar1.Value -= 5

End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button3.Click

ProgressBar1.Value = 100

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button4.Click

ProgressBar1.Value = 0

End Sub

This is code for buttons now we will see how we can work with progress bar with mouse wheel

scrolling. Select MouseWheel event from form1 events.Now write simple code in this event:

Fine9™

Page 21:  .Net Project Lalatendu

Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As

System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel

If e.Delta > -1 Then

If ProgressBar1.Value < 100 Then

ProgressBar1.Value += 5

End If

Else

If ProgressBar1.Value > 0 Then

ProgressBar1.Value -= 5

End If

End If

End Sub

Now in if condition you see that e.delta > -1 this is important for us when we scroll mouse one

time control comes in this event and if we scroll wheel up side e.delta value will < 0 and if we

scroll down side e.delta value > 0. Only remember these things in mind. Now see this condition

ProgressBar1.Value < 100 we are handling the exception and also in ProgressBar1.Value > 0

because progressbar value should be in range of progressbar1.minimum and

progressbar1.maximum.

Button Control

e most popular control in Visual BasicOne of th is the Button Control (previously Command

e click and release to perform some action. Buttons are

code, say, for sending data entered in the form to the

atabase and so on. The default event of the Button is the Click event and the Button class is

uttonBase class which is based on the Control class.

nt

he default event of the Button is the Click event. When a Button is clicked it responds with

Event. The Click event of Button looks like this in code:

orking with Buttons

F4

Control). They are the controls which w

used mostly for handling events in

d

based on the B

Button Eve

T

the Click

W

Well, it's time to work with Buttons. Drag a Button from the toolbox onto the Form. The

default text on the Button is Button1. Click on Button1 and select it's properties by pressing

Fine9™

Page 22:  .Net Project Lalatendu

on the keyboard or by selecting

View->Properties Window from the main menu. That displays the Properties for Button1.

Important Properties of Button1 from Properties Window:

Appearance

Appearance section of the properties window allows us to make changes to the appearance of

the help of BackColor and Background Imagethe Button. With properties we can set a

background color and a background image to the button. We set the font color and font style

for the text that appears on button with ForeColor and the Font property. We change the

appearance style of the button with the FlatStyle property. We can change the text that a

on button with the Text property and with the TextAlign property we can set where on the

button the text should appear from a predefined

ppears

age of a Button. Below is the im

Creating a Button in Code

CheckBox

CheckBoxes are those controls which gives us an option to select, say, Yes/No or True/False. A

checkbox is clicked to select and clicked again to deselect some option. When a checkbox is

selected a check (a tick mark) appears indicating a

selection. The CheckBox control is based on

the TextBoxBase class which is based on the Control class. Below is the image of a Checkbox.

Fine9™

Page 23:  .Net Project Lalatendu

Notable Properties

e

heckAlign: Used to set the alignment for the CheckBox from a predefined list.

Checked: Default value is False, set it to True if you want the CheckBox to be displayed as

checked.

CheckState: Default value is Unchecked. Set it to True if you want a check to appear. When set

to Indeterminate it displays a check in gray background.

FlatStyle: Default value is Standard. Select the value from a predefined list to set the style of the

checkbox.

RadioButton Event

The default event of the RadioButton is the CheckedChange event which looks like this in

code:

ListBox

The ListBox control displays a list of items from which we can make a selection. We can select

one or more than one of the items from the list. The ListBox control is based on the

ich is based on the Control class. The image below displays a ListBox.

Important properties of the CheckBox in the Appearance section of the properties window are:

Appearance: Default value is Normal. Set the value to Button if you want the CheckBox to b

displayed as a Button.

BackgroundImage: Used to set a background image for the checkbox.

C

ListControl class wh

Fine9™

Page 24:  .Net Project Lalatendu

Notable Properties of the ListBox

In the Behavior Section

HorizontalScrollbar: Displays a horizontal scrollbar to the ListBox. Works when the ListBox

has MultipleColumns.

MultiColumn: The default value is set to False. Set it to True if you want the list box to display

multiple columns.

ScrollAlwaysVisible: Default value is set to False. Setting it to True will display both Vertical

and Horizontal scrollbar always.

SelectionMode: Default value is set to one. Select option None if you do not any item to be

selected. Select it to MultiSimple if you want multiple items to be selected. Setting it to

MultiExtended allows you to select multiple items with the help of Shift, Control and arrow

keys on the keyboard.

Sorted: Default value is set to False. Set it to True if you want the items displayed in the

order. ListBox to be sorted by alphabetical

ComboBox

ComboBox is a combination of a TextBox and a ListBox. The ComboBox displays an editing

field (TextBox) combine

ComboBox displays data in a drop-down style format. The ComboBox class is derived from the

ListBox class. Below

d with a ListBox allowing us to select from the list or to enter new text.

is the Image of a ComboBox.

Fine9™

Page 25:  .Net Project Lalatendu

Notable properties of the ComboBox

The DropDownStyle property in the Appearance section of the properties window allows us to

set the look of the ComboBox. The default value is set to DropDown which means that the

ComboBox displays the Text set by it's Text property in the Textbox and displays it's items in

the DropDownListBox below. Setting it to simple makes the ComboBox to be displayed with a

TextBox and the list box which doesn't drop down. Setting it to DropDownList makes the

ComboBox to make selection only from the drop down list and restricts you from entering any

text in the textbox.

rted property which is set to False by Default.

We can sort the ComboBox with it's So

We can add items to the ComboBox with it's Items property.

TreeView

The tree view control is used to display a hierarchy of nodes (both parent, child). You can

expand and collpase these nodes by clicking them. This control is similar to Windows Explorer

which displays a tree view in it's left pane to list all the folders on the hard disk. Below is the

image of a Tree View control.

Fine9™

Page 26:  .Net Project Lalatendu

Notable Properties of TreeView

Bounds: Gets the actual bound of the tree node

Checked: Gets/Sets whether the tree node is checked

FirstNode: Gets the first child tree node

FullPath: Gets the path from the root node to the current node

ImageIndex: Gets/Sets the image list index of the image displayed for a node

Index: Gets the location of the node in the node collection

IsEditing: Gets whether the node can be edited

IsExpaned: Gets whether the node is expaned

IsSelected: Gets whether the node is selected

LastNode: Gets the last child node

NextNode: Gets the next sibling node

NextVisibleNode: Gets the next visible node

NodeFont: Gets/Sets the font for nodes

Nodes: Gets the collection of nodes in the current node

Parent: Gets the parent node of the current node

PrevNode: Gets the previous sibling node

PrevVisibleNode: Gets the previous visible node

TreeView: Gets the node's parent tree view

Fine9™

Page 27:  .Net Project Lalatendu

GroupBox Control

As said above, Groupboxes are used to Group controls. GroupBoxes display a frame around

them and also allows to display captions to them which is not possible with the Panel control.

The GroupBox class is based on the Control class.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_

As System.EventArgs) Handles MyBase.Load

Dim GroupBox1 As New GroupBox()

Dim CheckBox1 As New CheckBox()

Dim Label1 As New Label()

GroupBox1.Location = New Point(30, 60)

GroupBox1.Size = New Size(200, 264)

GroupBox1.Text = "InGroupBox"

'setting the caption to the groupbox

Me.Controls.Add(GroupBox1)

Fine9™

Page 28:  .Net Project Lalatendu

CheckBox1.Size = New Size(95, 45)

CheckBox1.Location = New Point(20, 30)

CheckBox1.Text = "Checkbox1"

label1.Size = New Size(100, 50)

Label1.Location = New Point(20, 40)

Label1.Text = "CheckMe"

GroupBox1.Controls.Add(CheckBox1)

GroupBox1.Controls.Add(Label1)

'adding the label and checkbox to the groupbox

End Sub

ToolTip

ToolTips are those small windows which display some text when the mouse is over a control

giving a hint about what should be done with that control. ToolTip is not a control but a

component which means that when we drag a ToolTip from the toolbox onto a form it will be

displayed on the component tray. Tooltip is an Extender provider component which means that

when you place an instance of a ToolTipProvider on a form, every control on that form receives

a new property. This property can be viewed and set in the properties window where it appears

as Tooltip on n, where n is the name of the ToolTipProvider.

To assign ToolTip's with controls we use it's SetToolTip method.

Notable property of the ToolTip is the Active property which is set to True by default and

which allows the tool tip to be displayed.

Setting a ToolTip

Assume that we have a TextBox on the form and we want to display some text when your mouse

is over the TextBox. Say the text that should appear is "Do not leave this blank". The code for

that looks like this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_

As System.EventArgs) Handles MyBase.Load

ToolTip1.SetToolTip(TextBox1, "Do not leave this blank")

End Sub

Fine9™

Page 29:  .Net Project Lalatendu

The image below displays output from above code.

User Controls

User Controls are the controls which are created by the user and they are based on the class

System.Windows.Forms.UserControl. Like standard controls, user controls support

properties, methods and events. Once a user control is created it can be added to any form or

any number of forms like all other controls.

Creating a User Control

To create a user control select File->New->Project->Visual Basic Projects and select Windows

Control Library from the templates and click OK. Alternatively, you can add user control to the

existing project by selecting Project->Add User Control. The image below displays the new

project dialogue to add a User Control project.

Fine9™

Page 30:  .Net Project Lalatendu

The form that opens after clicking OK looks like the image below. It looks similar to a normal

form.

Creating a User Control with Example

Drag a Label and a TextBox control from the toolbox onto the new user control form. The

image below displays that.

Fine9™

Page 31:  .Net Project Lalatendu

Double-click the user control form to open it's code behind file. In the code behind file type the

following code below the Load event (under End Sub) of UserControl1 to set the property of

the user control which is being created.

Fine9™

Page 32:  .Net Project Lalatendu

ADO.NET

ADO.NET was designed to meet the needs of this new programming model:

disconnected data architecture, tight integration with XML, common data representation with

the ability to combine data from multiple and varied data sources, and optimized facilities for

interacting with a database, all native to the .NET Framework.

ADO.Net Overview

• ADO.NET provides consistent access to data sources such as Microsoft SQL Server, as

well as data sources exposed via OLE DB and XML. Data-sharing consumer

applications can use ADO.NET to connect to these data sources and retrieve,

manipulate, and update data.

• ADO.NET cleanly factors data access from data manipulation into discrete

components that can be used separately. ADO.NET includes .NET data providers for

connecting to a database, executing commands, and retrieving results. Those results are

either processed directly, or placed in an ADO.NET DataSet object in order to be

exposed to the user in an ad-hoc manner, combined with data from multiple sources, or

remoted between tiers. The ADO.NET DataSet object can also be used independently

of a .NET data provider to manage data local to the application or sourced from XML.

• The ADO.NET classes are found in System.Data.dll, and are integrated with the XML

classes found in System.Xml.dll.

ADO .Net Architecture

1. Data processing has traditionally relied primarily on a connection-based, two-tier model. As

data processing increasingly uses multi-tier architectures, programmers are switching to a

disconnected approach to provide better scalability for their applications

2. ADO.NET leverages the power of XML to provide disconnected access to data.

3. ADO.NET and the XML classes in the .NET Framework join in the DataSet object. The

DataSet can be populated with data from an XML source, whether it is a file or an XML stream.

The DataSet can be written as World Wide Web Consortium (W3C) compliant XML,

including its schema as XML Schema definition language (XSD) schema, regardless of the

source of the data in the DataSet. Because the native serialization format of the DataSet is

Fine9™

Page 33:  .Net Project Lalatendu

XML, it is an excellent medium for moving data between tiers making the DataSet an optimal

choice for remoting data and schema context to and from an XML Web service.

ADO.NET DataSet:

The DataSet object is central to supporting disconnected, distributed data scenarios with

ADO.NET. The DataSet is a memory-resident representation of data that provides a

consistent relational programming model regardless of the data source. It can be used with

multiple and differing data sources, used with XML data, or used to manage data local to the

application. The DataSet represents a complete set of data including related tables, constraints,

and relationships among the tables.

The DataSet can also persist and reload its contents as XML and its schema as XML Schema

definition language (XSD) schema.

ADO.NET Components:

Data Set: The ADO.NET components have been designed to factor data access from

data manipulation. There are two central components of ADO.NET that accomplish

this: the DataSet, and the .NET data provider, which is a set of components including

the Connection, Command, DataReader, and DataAdapter objects.

Data Table: The DataSet contains a collection of one or more DataTable objects made

up of rows and columns of data, as well as primary key, foreign key, constraint, and

relation information about the data in the DataTable objects

.NET Data Providers:Itis used for connecting to a database, executing commands, and

retrieving results. Those results are either processed directly, or placed in an

ADO.NET DataSet in order to be exposed to the user in an ad-hoc manner, combined

with data from multiple sources, or remoted between tiers. The .NET data provider is

designed to be lightweight, creating a minimal layer between the data source and the

code, increasing performance without sacrificing functionality.

Core Objects of .Net Data Provider:

Object

Description

Connection

Establishes a connection to a specific data source.

Fine9™

Page 34:  .Net Project Lalatendu

Command

Executes a command against a data source. Exposes Parameters and

can execute within the scope of a Transaction from a Connection.

DataReader

Reads a forward-only, read-only stream of data from a data source.

DataAdapter

Populates a DataSet and resolves updates with the data source.

Using DataReaders, SQL Server

In this section we will work with databases in code. We will work with ADO .NET objects in

code to create connections and read data using the data reader. We will see how to connect

using our own connection objects, how to use the command object and so on. The namespace

that needs to be imported when working with SQL Connections is System.Data.SqlClient.

This section works with common database operations like insert, select, update and delete

commands.

Working with SQL Server

When working with SQL Server the classes with which we work are described below.

TheSqlConnectionClass

TheSqlConnection class represents a connection to SQL Server data source. We use OleDB

connection object when working with databases other than SQL Server. Performance is the

major difference when working with SqlConnections and OleDbConnections. Sql connections

are said to be 70% faster than OleDb connections.

Fine9™

Page 35:  .Net Project Lalatendu

TheSqlCommandClass

TheSqlCommand class represents a SQL statement or stored procedure for use in a database

with SQL Server.

TheSqlDataAdapterClass

TheSqlDataAdapter class represents a bridge between the dataset and the SQL Server

database. It includes the Select, Insert, Delete and Update commands for loading and updating

the data.

TheSqlDataReaderClass

TheSqlDataReader class creates a data reader to be used with SQL Server.

DataReaders

A DataReader is a lightweight object that provides read-only, forward-only data in a very fast

and efficient way. Using a DataReader is efficient than using a DataAdapter but it is limited.

Data access with DataReader is

read-only, meaning, we cannot make any changes (update) to data and forward-only, which

means we cannot go back to the previous record which was accessed. A DataReader requires the

exclusive use of an active connection for the entire time it is in existence. We instantiate a

DataReader by making a call to a Command object's ExecuteReader command. When the

DataReader is first returned it is positioned before the first record of the result set. To make the

first record available we need to call the Read method. If a record is available, the Read method

moves the DataReader to next record and returns True. If a record is not available the Read

method returns False. We use a While Loop to iterate through the records with the Read

method.

Sample Code

Code to Retrieve Data using Select Command

The following code displays data from Discounts table in Pubs sample database.

Imports System.Data.SqlClient

Public Class Form1 Inherits System.Windows.Forms.Form

Dim myConnection As SqlConnection

Dim myCommand As SqlCommand

Dim dr As New SqlDataReader()

'declaring the objects

Fine9™

Page 36:  .Net Project Lalatendu

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As

System.EventArgs)_

Handles MyBase.Load

myConnection = New

SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")

'establishing connection. you need to provide password for sql server

Try

myConnection.Open()

'opening the connection

myCommand = New SqlCommand("Select * from discounts",

myConnection)

'executing the command and assigning it to connection

dr = myCommand.ExecuteReader()

While dr.Read()

'reading from the datareader

MessageBox.Show("discounttype" &dr(0).ToString())

MessageBox.Show("stor_id" &dr(1).ToString())

MessageBox.Show("lowqty" &dr(2).ToString())

MessageBox.Show("highqty" &dr(3).ToString())

MessageBox.Show("discount" &dr(4).ToString())

'displaying the data from the table

End While

dr.Close()

myConnection.Close()

Catch e As Exception

End Try

End Sub

End Class

The above code displays records from discounts table in MessageBoxes.

Standard Security

Fine9™

Page 37:  .Net Project Lalatendu

Data Source=myServerAddress;Initial Catalog=myDataBase; User

Id=myUsername;Password=my Password;

Use serverName\instanceName as Data Source to connect to a specific SQL Server

instance.

Are you using SQL Server 2005 Express? Don't miss the server name syntax

Servername\SQLEXPRESS where you substitute Servername with the name of the

computer where the SQL Server 2005 Express installation resides.

Standard Security alternative syntax

This connection string produce the same result as the previous one. The reason to include

it is to point out that some connection string keywords have many equivalents.

Server=myServerAddress;Database=myDataBase;User

ID=myUsername;Password=myPassword;Trusted_Connection=False;

Trusted Connection

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

Trusted Connection alternative syntax

This connection string produce the same result as the previous one. The reason to include

it is to point out that some connection string keywords have many equivalents.

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

Connecting to an SQL Server instance

The syntax of specifying the server instance in the value of the server key is the same for all

connection strings for SQL Server.

Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;

Trusted Connection from a CE device

Often a Windows CE device is not authenticated and logged in to a domain. To use SSPI or

trusted connection / authentication from a CE device, use this connection string.

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User

ID=myDomain\myUsername;Password=myPassword;

Connection string to connect to Sql Server database

VB 2005

Given below is the connection string for connecting a Visual Basic. Net application to an Sql

Server database.

Dim connectionString As String = “Data Source=SYS2;” + “integrated security=SSPI;” +

“database=FinAccounting”

Fine9™

Page 38:  .Net Project Lalatendu

Connection string to connect to Sql Server database which is on a remote server

Below is an example of a connection string used to access a sql server database which is on the

remote web server on the internet, using C# code in an .aspx file.

string connectionString = "Data Source=201.73.323.39;database=FinAccounting;User

ID=sssabc123;Password=scss456;";

In the above code, we assign the IP address of the server to the ‘Data Source’, assign the name of

the database, assign the username and the password. The above code is used to connect to a

database hosted on a web server.

Let us see, what is a connection object, as the connection string is a property of the Connection

Object.

Connection Object

The Connection object establishes a connection to the database. Two of the most common

Connection objects used are OleDbConnection and SqlConnection. Both the SqlConnection

and OleDbConnection are namespaces and are inherited from the IdbConnection object. The

commonly used property of the Connection object is the Connection string property.

ConnectionString property

This property is used to provide information, such as the data source and database name, that is

used to establish the connection with the database.

There are two ways of setting the Connection string property.

1. Using a parameterized Constructor

2. Using the default constructor

Setting the Connection String property using a parameterized Constructor

Visual basic 2005

Imports System.Data

Imports System.Data.SqlClient

Public Sub GetData()

Fine9™

Page 39:  .Net Project Lalatendu

Dim connectionString As String = “Data Source=SYS2;” +

“integrated security=SSPI;” + “database=FinAccounting”

Dim myConnection As Sqlconnection =

New SqlConnection(connectionString)

myConnection.Open()

End Sub

In this method, we are taking advantage of the SqlConnection object’s parameterized

constructor to set the ConnectionString property directly, at the same time as it is instantiated.

Setting the Connection String property using the default constructor

In this method, we use the default constructor and then later set the ConnectionString property

separately.

Visual basic 2005

Imports System.Data

Imports System.Data.SqlClient

Public Sub GetData()

Dim myConnection As Sqlconnection = New SqlConnection()

myConnection.ConnectionString=“Data Source=SYS2;” + “integrated security=SSPI;” +

“database=FinAccounting”

myConnection.Open()

End Sub

Note that the connection string must always be set before the connection is opened, and cannot

be changed after the connection is open.

Retrieving records with a Console Application

Imports System.Data.SqlClient

Imports System.Console

Module Module1

Dim myConnection As SqlConnection

Dim myCommand As SqlCommand

Dim dr As SqlDataReader

Sub Main()

Try

myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")

Fine9™

Page 40:  .Net Project Lalatendu

'you need to provide password for sql server

myConnection.Open()

myCommand = New SqlCommand("Select * from discounts", myConnection)

dr = myCommand.ExecuteReader

Do

While dr.Read()

WriteLine(dr(0))

WriteLine(dr(1))

WriteLine(dr(2))

WriteLine(dr(3))

WriteLine(dr(4))

' writing to console

End While

Loop While dr.NextResult()

Catch

End Try

dr.Close()

myConnection.Close()

End Sub

End Module

INSERT,UPDATE,DELETE,SHOW,CLEAR,DATAGRID

Imports System.Data.SqlClient

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button1.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("insert into sandhya values('" &

TextBox1.Text & "','" & TextBox2.Text & "'," & TextBox3.Text & ",'" & TextBox4.Text &

"')", con)

If com.ExecuteNonQuery Then

MsgBox("data saved")

Else

Fine9™

Page 41:  .Net Project Lalatendu

MsgBox("data not saved")

End If

con.Close()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button2.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("delete from sandhya where

name='sandhya'", con)

com.ExecuteNonQuery()

MsgBox("deleted")

con.Close()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button3.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("update sandhya set name = '" &

TextBox1.Text & "' where age=" & TextBox3.Text & " ", con)

com.ExecuteNonQuery()

MsgBox("updated")

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button4.Click

Fine9™

Page 42:  .Net Project Lalatendu

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button5.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("select * from sandhya where name='" &

textbox5.text & "'", con)

Dim rdr As SqlDataReader

rdr = com.ExecuteReader

If rdr.Read Then

TextBox1.Text = rdr("name").ToString

TextBox2.Text = rdr("address").ToString

TextBox3.Text = rdr("age").ToString

TextBox4.Text = rdr("course").ToString

End If

rdr.Close()

con.Close()

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button6.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Fine9™

Page 43:  .Net Project Lalatendu

Dim da As SqlDataAdapter = New SqlDataAdapter("select * from sandhya where name='"

& TextBox5.Text & " ' ", con)

Dim ds As DataSet = New DataSet()

da.Fill(ds, "details")

con.Close()

DataGridView1.DataSource = ds

DataGridView1.DataMember = "details"

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles MyBase.Load

End Sub

End Class

CRYSTAL REPORT

Crystal Reports is a business intelligence application used to design and generate reports from a

wide range of data sources. Several other applications, such as Microsoft Visual Studio, bundle

an OEM version of Crystal Reports as a general purpose reporting tool.Crystal Reports became

the de facto standard report writer when Microsoft released it with Visual Studio.

Unlike previous versions of Visual Studio, Crystal Reports is an integral part of Visual Studio

.NET and ships as a part of it. By making Crystal Reports a part of Visual Studio .NET suite,

Fine9™

Page 44:  .Net Project Lalatendu

Microsoft has added one more useful tool to the Visual Studio family. In this article, I will show

you how to create a simple report using Crystal Reports and Visual Studio .NET. In my

following article, I shall dig more into Crystal Reports .NET.

For this i have created two tables in database named Employees and Projects and fetching data

from both tables

I've grouped results by Department name using group expert in crystal reports and put a

dropdown on the form to select project name to display related report.

Employee table schema

ID int

FirstName varchar(50)

LastName varchar(50)

Department varchar(50)

ProjectID numeric(18, 0)

Expenses money

Fine9™

Page 45:  .Net Project Lalatendu

Projects table schema

ProjectID numeric(18, 0)

ProjectName varchar(50)

Create a new project in VS and go to solution explorer and add new item > crystal report.

Select Blank report option from the wizard window

Now click on CrystalReports menu and select DataBase Expert

Now in next window expand Create new connection section and OLEDB(ADO) and in next

window select SQL Native Client

Fine9™

Page 46:  .Net Project Lalatendu

Enter you SQL Server name , username and password , select database name from the

dropdown and click on ok

In next window expand to find your tables and add them in right pane

Fine9™

Page 47:  .Net Project Lalatendu

Click OK to finish

Now Right Click on Group Name Fields in Field Explorer and Select Group Expert.

In group expert box select the field on which you want data to be grouped.

Design your report by dragging the fields in section3 (Details)

my design look like this

Fine9™

Page 48:  .Net Project Lalatendu

In the form add a combobox and drag and drop CrystalReport Viewer from toobox. click on

smart tag and choose the report we created earlier (CrystalReport1.rpt)

ASP.NET

ASP.NET is a programing technology based on .NET framework & is used for create a

dynamic web application which provides a unified web development model that includes the

services necessary for developers to build enterprise-class web application. While ASP.NET is

largely syntax compatible with ASP, it also provides a new programing model and infrastructure

for more scalable and stable applications that help provide greater protection.

ASP.NET is a compiled, .NET-based environment; we can author applications in any

.NET compatible language, including VB.NET, c# And Jscript .NET. Developers can easily

access the benefits of these technologies, which include the manage common language runtime

environment, type safety, inheritance & so on.

ASP.NET is one of the components available in Microsoft visual studio .NET. ASP

broadly speaking is Active Server pages.ASP is used to create web applications taking all the

features of .NET.

FEATURES OF .NET:

Fine9™

Page 49:  .Net Project Lalatendu

New ASP .NET infrastructure:

There is a new concept of managed code that runs in NGWS runtime, which manages

the execution of the code.

Increased performance:

Pages in ASP.NET are compiles into a .NET class when they are run for first time.

Separation of HTML from ASP code:

It was often said that JSP is offers separation of code and markup, which is not there in

ASP.

Better Integration with XML:

Web services sends data back and forth in XML format.

Security:

Form based authentication:

We can do our own custom login screens and own credential checking and still have ASP.NET

Handle authenticating the user, redirecting unauthorized users back login page, cookie

management all other we have to build.

STATIC WEB PAGE:

A static web page is a web page that is deliver to the user exactly as stored in contrast to

dynamic web pages which are generated by a web application. Static web pages are often HTML

documents stored as files in the file system and made available by the web server over HTTP.

DYNAMIC PAGE:

Fine9™

Page 50:  .Net Project Lalatendu

Typically written in various scripting languages or technologies ASP, PHP, PEARL or JSP.

WEB SERVER:

A web server is a computer program that delivers (serves) content, such as web pages,

using the HTTP, over the world wide web. The term web server can also refer to the computer

or virtual machine running the program.

The primary function of a web server is to deliver web pages to client .This means delivery of

HTML documents and any additional content that may be included by a document, such as

image, style

sheets and Java scripts.

New ASP.NET infrastructure:-

There's a new concept of managed code that runs in NGWS runtime, which manages

the execution of the code. And also the amount of coding is also reduced with two new

concepts.

First is code behind: once ASP.PAGE is complied, it creates a base class from which

pages can inherit. And other is user controls, which allows the user to re-use sections of their own

code.

Increased performance:

Pages in ASP.NET are compiles into a .NET class when they are run for first time. The

class is stored in cache, which will be used for any future requests for the page. If the page is

changed, class is recompiled and cached version changes automatically.

Separation of HTML from ASP Code:

It was often said that JSP is offers separation of code and markup, which is not there in ASP.

With the improvement in ASP.NET it impossible to remove ASP scripting from the page. This

makes ASP.NET applications now easier to maintain and update.

Better Integration with XML:

Web services sends data back and forth in XML format. So creation of web services has led to

the services whose specific purpose is generation and utilization of XML files. Upgradation of

ADO to ADO.NET also means greater support for XML.

Quicker and Easier Development:

The one thing any platform should do is to provide a solid foundation that we can build upon.

With ASP.NET we get foundation where repetitive and annoying task are done for us.

Fine9™

Page 51:  .Net Project Lalatendu

INSERT,UPDATE,DELETE,SHOW,CLEAR,GRIDVIEW

Imports System.Data

Imports System.Data.SqlClient

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

btn1.Click

Dim con As SqlConnection = New SqlConnection("data source=(local);initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand(" insert into sandhya values('" & txt1.Text

& "','" & txt2.Text & "'," & txt3.Text & ",'" & txt4.Text & "')", con)

If com.ExecuteNonQuery() Then

MsgBox("data saved")

Else

MsgBox("data not saved")

End If

End Sub

Protected Sub btn2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

btn2.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("delete from sandhya where

name='sandhya'", con)

com.ExecuteNonQuery()

Fine9™

Page 52:  .Net Project Lalatendu

MsgBox("deleted")

con.Close()

End Sub

Protected Sub btn3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

btn3.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("update sandhya set name = '" & txt1.Text

& "' where age=" & txt3.Text & " ", con)

com.ExecuteNonQuery()

MsgBox("updated")

End Sub

Protected Sub btn6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

btn6.Click

txt1.Text = ""

txt2.Text = ""

txt3.Text = ""

txt4.Text = ""

End Sub

Protected Sub btn4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

btn4.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim com As SqlCommand = New SqlCommand("select * from sandhya where name='" &

txt5.text & "'", con)

Dim rdr As SqlDataReader

rdr = com.ExecuteReader

If rdr.Read Then

Fine9™

Page 53:  .Net Project Lalatendu

txt1.Text = rdr("name").ToString

txt2.Text = rdr("address").ToString

txt3.Text = rdr("age").ToString

txt4.Text = rdr("course").ToString

End If

rdr.Close()

con.Close()

End Sub

Protected Sub btn5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

btn5.Click

Dim con As SqlConnection = New SqlConnection("data source=(local); initial

catalog=Ravenshaw;trusted_connection=yes")

con.Open()

MsgBox("connected")

Dim da As SqlDataAdapter = New SqlDataAdapter("select * from sandhya where name='"

& txt5.Text & " ' ", con)

Dim ds As DataSet = New DataSet()

da.Fill(ds, "details")

con.Close()

btn7.DataSource = ds

btn7.DataBind()

End Sub

End Class

Fine9™

Page 54:  .Net Project Lalatendu

Asp Control Statements

If...Then Select...Case For...Next For Each....Next

Do...While While...Wend Functions & Subroutine Exit

Asp Control statements are statements that control the execution order.In asp there are three

types of control statements. Conditional statements, Looping control , and jumping control.

Asp Conditional statements

1) If....Then statement

Asp if statement is used to help a programmer determine whether to execute one set of code or

another. The syntax for an if statement is the following:

<%

If (expression) Then

Fine9™

Page 55:  .Net Project Lalatendu

'some code

Else

'some other code

End If

%>

Remember the following points while using If...Then

� The result of expression must be True or False.

� WE can evaluate only one expression in an If..Then structure.

� If there are more than on line of action statements then you must use the End if .

� We can use nested if statements to check multiple conditions. Just remember to include and

"End If" with each condition you test for. If you forget to include this the ASP Runtime will

give you an error.

Eg:

<%

If Num = 100 Then

Response.Write("Cograt!! You got matching number")

Else

Response.Write("Sorry!!.Try Again")

End If

%>

2) Select Case statement

Select statements are useful when you want to test one condition and need to make a choice

among several answers. The syntax is:

<%

Select Case num

Case "1"

Response.Write("num=1")

Case "2"

Response.Write("num=2")

Case "3"

Response.Write("num=3")

Fine9™

Page 56:  .Net Project Lalatendu

Case "4"

Response.Write("num=4")

Case Else

Response.Write("num equals something else...")

End Select

%>

The first line states that you want compare the values to variable 'num'.Then ASP test the

contents of variable against the values shown in the 'case' line.If it finds a match it will execute

the code upto the next case line and then jumpdown to first line after End select.Remember

that it is case sensitive , ie. if we are looking for a variable 'FL' it is not same as 'Fl'. The

following example gives an improved method of case select.

<%

Select Case strstate

Case "FL" , "Fl" ,"fl"

Response.Write("Your state is Florida")

Case "NJ" , "Nj" ,"nj"

Response.Write("Your state is NewJersey")

Case "NY" ,"Ny" , "ny"

Response.Write("Your state is NewYork")

Case "CA" ,"Ca","ca"

Response.Write("Your state is California")

Case Else

Response.Write("Your state not listed here.")

End Select

%>

Asp Looping Control

1) For...Next Statement

The syntax is:

<%

For Count = StartCount to EndCount

----------

Fine9™

Page 57:  .Net Project Lalatendu

----------

Next

%>

The for next staement has three parts.The first line describes how many times to repeat the

loop.Second is a set of lines with action statements that carry out the task you want to

repeat.Last line is end action statement and tells ASP to go back and repeat action statements

again.

Eg:

<%

For i = 10 to 14

response.write("This is " & i &" th line<hr>"

next

%>

2) For Each...Next statement

The FEN loop works identical to For..Next statement except that it is used to loop through

collections like recordsets, form collections, or arrays.In this case we don't have to specify the

number of times we want to loop.

Eg:

<%

Dim strfrutes(3)

strfrutes(0) = "grapes"

strfrutes(1) = "oranges"

strfrutes(2) = "apples"

strfrutes(3) = "mangos"

For each ft In strfrutes

tesponse.write ft

Next

%>

Fine9™

Page 58:  .Net Project Lalatendu

3)Do...While staement

It is used to repeat the loop while specified condition exist. The difference between For Loop

and Do Loop is that

the For Loop did a specific action a certain number of times where as the Do Loop continues to

do a specific action until the supplied statement is found to be true.

Eg:

<%

i=10

Do While i<14

response.write("This is " & i & "th line.<hr>")

i=i+1

Loop

%>

4)While...Wend Statement

The While...Wend loop is very similar to the Do loop. This loop performs the requested

action until a condition is met. The only difference is a small amount of syntax.

<%

While {Condition}

........

Wend

%>

The While loop is commonly used to loop through a recordset that has been returned from a

database. That we will se in later portion.

Jumping Control

Asp Functions And Subrouteins

Fine9™

Page 59:  .Net Project Lalatendu

In Asp function is a group of lines of code in a program that performs a specific task . A Sub is a

group of lines of code in a program that performs a specific task. A function returns a value and

a sub does not return a value.

Asp Functions

<%

Function functionName(parameter)

...............

Some code

............

End Function

%>

To use the function in the main progrm just type the named function followed by the

parentheses.

Asp Exit statement

Using the Exit statement you can force the flow of your program to exit the current set of logic

it is in. An example of when you might want to do this is when you have a few nested if

statements. Once you are in the if statements you check a certain condition and find it to be

false. At this point you want to flow of your program to exit out of the current sub routine. With

the Exit statement you can do this.

Eg:

<%

i=10

Do While i<14

If i = 13 Then

Response.Write("Exiting Do loop...")

Exit Do

End If

response.write("This is " & i & "th line.<hr>")

i=i+1

Loop

Result: This code will loop through until i equals 13, then it will print "Exiting Do

Fine9™

Page 60:  .Net Project Lalatendu

loop..."

and exit the loop.

Request, Response Objects

Request and Response objects represent information coming into the Web server from the

browser and information going out from the server to the browser. The Request object is called

the input object and the Response object is called the output object.

Response Object

As mentioned above, the Response object represents a valid HTTP response that was received

from the server. The response header properties are read-only. Notable properties of the object

are as follows:

Body: Gets the body of the HTTP response. Only the portion of the body stored in the

response buffer is returned

BytesRecv: Gets the number of bytes the client received in the response

BytesSent: Gets the number of bytes send in the HTTP request

CodePage: Gets or sets the code page used for setting the body of the HTTP response

ContentLength: Gets the size, in bytes, of the response body

Headers: Gets a collection of headers in the response

HeaderSize: Gets the combined size, in bytes, of all the response headers

HTTPVersion: Gets the HTTP version used by the server for this response

Path: Gets the path that was requested

Port: Gets the server port used for the request

ResultCode: Gets the server's response status code

Server: Gets the name of the server that sent the response

TTFB: Gets the number of milliseconds that have passed before the first byte of the response

was received

TTLB: Gets the number of milliseconds that passed before the last byte of the response was

received

UseSSL: Checks whether the server and client used an SSL connection for the request and

response

Fine9™

Page 61:  .Net Project Lalatendu

Sample Code

The following sample code assumes that you have a Button control and four RadioButtoin

controls with a common GroupName property on a Web Form. The user will be sent to a new

Web Page if he makes a selection from one of the radio button's and hits the Submit button.

You can view the live demo at the bottom of this page.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As_

System.EventArgs) Handles MyBase.Load

Dim ccc As String = "Response Object"

Response.Write(ccc)

Response.Write("Using Response object")

'using the response object's write method to write some text

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_

System.EventArgs) Handles Button1.Click

If RadioButton1.Checked = True Then

Response.Redirect("http://www.google.com")

'using the response object's redirect method to redirect the user to another

web page

ElseIf RadioButton2.Checked = True Then

Response.Redirect("http://www.amazon.com")

ElseIf RadioButton3.Checked = True Then

Response.Redirect("http://www.yahoo.com")

ElseIf RadioButton4.Checked = True Then

Response.Redirect("http://www.startvbdotnet.com")

End If

End Sub

Request Object

As mentioned above, the Request object represents an HTTP request before it has been sent to

the server. Notable properties of this object are as follows:

Body: Gets/Sets the HTTP request body

CodePage: Gets/Sets the code page for the request body

Fine9™

Page 62:  .Net Project Lalatendu

EncodeBody: Gets/Sets whether ACT automatically URL encodes the request body

EncodeQueryAsUTF8: Gets/Sets whether ACT automatically UTF-8 encodes the request's

query string

Headers: Gets the HTTP Headers collection object

HTTPVersion: Gets/Sets the HTTP version

Path: Gets/Sets the HTTP path

ResponseBufferSize: Gets/Sets the size of the buffer used to store the response body

Verb: Gets/Sets the HTTP method verb

Sample Code

Private Sub Page_Load(ByVal sender As System.Object,_

ByVal e As System.EventArgs) Handles MyBase.Load

Dim s As String = Request.UserHostAddress()

'request's user's host address and writes using the response object's write

method

Response.Write(s)

Dim a As String = Request.ApplicationPath()

'request's the application path

Response.Write(a)

Dim aa As String = Request.Browser.Browser

'request's the type of browser

Response.Write(aa)

Dim b As String = Request.CurrentExecutionFilePath

'request's the current execution path

Response.Write(b)

Dim c As String = Request.FilePath

'request's the path to the file that you are currently working with

Response.Write(c)

Dim cc As String = Request.HttpMethod

'gets the HttpMethod

Fine9™

Page 63:  .Net Project Lalatendu

Response.Write(cc)

If Request.Browser.Browser = "IE" Then

'checks to see if the browser is IE and if true displays a message

Response.Write("You are using IE")

Else

Response.Write("You are using some other browser")

End If

Response.Write("Your computer is/has the following" &

Request.Useragent)

'displays the user information about his computer

End Sub

The TextBox control is used to create a text box where the user can input text.

The TextBox Control

The TextBox control is used to create a text box where the user can input text.

The example below demonstrates some of the attributes you may use with the TextBox control:

Example

<html>

<body>

<form runat="server">

A basic TextBox:

<asp:TextBox id="tb1" runat="server" />

Fine9™

Page 64:  .Net Project Lalatendu

<br /><br />

A password TextBox:

<asp:TextBox id="tb2" TextMode="password" runat="server" />

<br /><br />

A TextBox with text:

<asp:TextBox id="tb4" Text="Hello World!" runat="server" />

<br /><br />

A multiline TextBox:

<asp:TextBox id="tb3" TextMode="multiline" runat="server" />

<br /><br />

A TextBox with height:

<asp:TextBox id="tb6" rows="5" TextMode="multiline"

runat="server" />

<br /><br />

A TextBox with width:

<asp:TextBox id="tb5" columns="30" runat="server" />

</form>

</body>

</html>

Show example »

A basic TextBox:

Fine9™

Page 65:  .Net Project Lalatendu

A password TextBox:

A TextBox with text: Hello World

A multiline TextBox:

A TextBox with height:

A TextBox with width:

ListBox Web Server Control

Creates a single-selection or multiselection list box.

<asp:ListBox id="Listbox1"

DataSource="<% databindingexpression %>"

DataTextField="DataSourceField"

DataValueField="DataSourceField"

AutoPostBack="True|False"

Rows="rowcount"

SelectionMode="Single|Multiple"

OnSelectedIndexChanged="OnSelectedIndexChangedMethod"

runat="server">

<asp:ListItem value="value" selected="True|False">

Text

</asp:ListItem></asp:ListBox>

Fine9™

Page 66:  .Net Project Lalatendu

Remarks

Use the ListBox control to create a list control that allows single or multiple item selection. Use

the Rows property to specify the height of the control. To enable multiple item selection, set

the SelectionMode property toListSelectionMode.Multiple.

To specify the items that you want to appear in the ListBox control, place a ListItem element

for each entry between the opening and closing tags of the ListBox control.

The ListBox control also supports data binding. To bind the control to a data source, first

create a data source, such as a System.Collections.ArrayList, that contains the items to display

in the control.

Next, use the Control.DataBindmethod to bind the data source to the ListBox control. Use

the DataTextField and DataValueField properties to specify which field in the data source to

bind to the Text and Value properties, respectively, of each list item in the control.

The ListBox control will now display the information from the data source.

If the SelectionMode property is set to ListSelectionMode.Multiple, determine the selected

items in the ListBoxcontrol by iterating through the Items collection and testing

the Selected property of each item in the collection. If theSelectionMode property is set

to ListSelectionMode.Single, you can use the SelectedIndex property to determine the index of

the selected item. The index can then be used to retrieve the item from the Items collection.

Fine9™

Page 67:  .Net Project Lalatendu

Lalatendu Keshari Swain Class Roll No: 307IST090 EXAM ROLL NO: IST/08-125 B.SC. IST 3rd YEAR RAVENSHAW UNIVERSITY

Fine9™