Você está na página 1de 71

M.I.E.

T POLYTECHNIC COLLEGE, TRICHY-7

DEPARTMENT OF COMPUTER ENGINEERING

.NET PROGRAMMING LABORATORY

SEMESTER: V

YEAR: III

CONTENTS
1.

Accept a character from console and check the case of the character.

2.

Write a program to accept any character from keyboard and display whether it is vowel
or not.

3.

Wrtie a VB.Net program to accept a string and convert the case of the characters.

4.

Develop a menu based VB.Net application to implement a text editor with cut, copy,
paste, save and close operations.

5.

Write a program to implement a calculator with memory and recall operations.

6.

Develop a Form in VB.NET to pick a date from Calendar control and display the day,
month, year details in seperate text boxes.

7.

Develop a VB.Net application to perform timer based quiz of 10 questions.

8.

Develop a VB.Net application using the File, Direcory and Directory controls to
implement a common dialog box.

9.

Develop a database application to store the details of students using ADO.NET

10

Develop a database application using ADO.NET to insert,modify, update and delete


operations.

11

Develop a VB.Net application using Datagrid to display records.

12

Develop a VB.Net application using Datagrid to add, edit and modify records.
ASP.NET

13.

Create a simple ASP.NET page to Output Text with a form, two HTML text boxes, an
HTML button, and an HTML <span> element. Create an event procedure for the button.

14.. Create a web controls to a page with three different controls to the ASP.NET page for
reserving rooms in hotel. The three controls are a button control, a label control, and a
drop-down list control.
15.

Create a application for Accessing a SQL Database by Using ADO.NET by connecting


to the SQL Server database and call a stored procedure. You then display the data in a
Repeater control.

16.

Create a web services application for calling a Web service for a hotel named full. And
you will call another Web service for a hotel named Empty, and then retrieve
information regarding room availability. The Web service for the Full hotel is named

Hotel_Full.dll. The Web service for the Empty hotel is named Hotel_Empty.dll. There
are five methods in each service.

1.

Reserve takes room types and start and end dates and returns a Boolean
value that indicates whether a room is available.
<WebMethod()>public Function Reserve (
strRoomType1 As String, strRoomType2 As String,
dtmStartDate As Date, dtmEndDate As Date) As Boolean

2.

Price returns a double value that is the cost of the rent for one day
<WebMethod()>public Function Price(
strRoomType1 As String) As Double

3.

Description returns a string that describes the hotel.


<WebMethod()>public Function Description() As String

4.

Room returns a string that describes the rooms of the hotel.


<WebMethod()>public Function Room() As String

5.

Food returns a string that describes the food available at the hotel.
<WebMethod()>public Function Food() As String.

Software Required:

(1) Net Frame Work

(ii) . VB,NET (iii) ASP.NET

Hardware Required: Computer with Pentium IV / Dual core Processors. 36 Nos

EX.NO:1

CHECKING THE CASE OF THE GIVEN CHARACTER

AIM

Create an application to accept a character from console and check the


case of the character
PROGRAM

1.Open Microsoft Visual studio and create a new windows application


2.View the Solution explorer. Right click on the project name And select
Properties
3. Set the Application Type as Console application
4. Edit the code in the Load event of Form1
5. Run the application by pressing F5 key or clicking Debug button

PROGRAM

Module Module1
Dim c As Char
Sub Main()
Console.WriteLine("Enter a character : ")
c = Console.ReadLine
If Char.IsUpper(c) Then
Console.WriteLine("Given Character is in Uppercase")
ElseIf Char.IsLower(c) Then
Console.WriteLine("Given Character is in Lowercase")
Else
Console.WriteLine("Given Character is not an alphabet")
End If
Console.ReadLine()
End Sub
End Module

SAMPLE OUTPUT
Enter a character : g
Given character is in Lowercase

RESULT
Thus the above program has been executed and verified.

EX.NO:2

CHECK THE GIVEN CHARACTER IS VOWEL OR NOT

AIM
Write a VB.NET program to accept any character from keyboard and
display whether it is vowel or not.
PROCEDURE

1. Open Microsoft visual studio and create a new windows


Application
2. Edit the code in the click event of Button1
3.. Run the application.

PROGRAM
Module Module1
Dim c As Char
Sub Main()
Console.WriteLine("Enter a character : "
C=Console.ReadLine
If c = "a" Or c = "A" Or c = "e" Or c = "E" Or c = "i" Or c = "I" Or c = "o" Or c = "O" Or c =
"u" Or c = "U" Then
Console.WriteLine("Given character is vowel")
Else
Console.WriteLine("Given character is not vowel")
End If
Console.ReadLine()
End Sub
End Module

SAMPLE OUTPUT

Enter a character : a

Given character is vowel

RESULT
Thus the above program has been executed and verified.

Ex.No:3.

CHANGING THE CASE OF THE GIVEN STRING

AIM
Write a VB.Net program to accept a string and convert the
Case of the character.

PROCEDURE

1. Open Microsoft Visual studio and create a new Windows application


2. Edit code in the click event of RadioButton1
TextBox2.Text = LCase(TextBox1.Text)
3. Edit the following code in the click event of RadioButton2
TextBox2.Text = UCase(TextBox1.Text)
4. Edit the following code in the click event of RadioButton3
TextBox1.Clear ()
TextBox2.Clear ()
5. Run the application

PROGRAM
Public Class Form1
Private Sub RadioLower_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioLower.CheckedChanged
TextBox2.Text = LCase(TextBox1.Text)
End Sub
Private Sub RadioUpper_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioUpper.CheckedChanged
TextBox2.Text = UCase(TextBox1.Text)
End Sub
Private Sub RadioClear_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioClear.CheckedChanged
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub ButClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButClose.Click
End
End Sub
End Class

PROPERTY WINDOW

Properties
Controls
Name

Text

Text Box

TextBox1

Text Box

TextBox2

Label

Label1

Changing the Case of The Given Text

Label

Label2

Enter Text

Label

Label3

Output

Radio Button

RadioLower

LowerCase

Radio Button

RadioUpper

UpperCase

Radio Button

RadioClear

Clear

Button

ButClose

Close the Application

RESULT
Thus the above program has been executed and verified.

EX.NO:4

ADDING MENU TO THE FORM

AIM
Develop a menu based VB.NET application to implement a text editor
With cut, copy, paste, saved and close operations.

PROCEDURE
1..Open Microsoft Visual studio and create a new Window
Application
2.Design a form
3.Edit the code in the event of all controls
4.Run the application

PROGRAM
Public Class Form1
Private Sub MnuNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuNew.Click
RTB.Clear()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Label1.Visible = False
TextBox1.Visible = False
ButSave.Visible = False
End Sub
Private Sub MnuSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MnuSave.Click
Label1.Visible = True
TextBox1.Visible = True
ButSave.Visible = True
End Sub
Private Sub ButSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButSave.Click
RTB.SaveFile(CStr(TextBox1.Text))
Label1.Visible = False
TextBox1.Visible = False
ButSave.Visible = False
End Sub
Private Sub MnuClose_Click(ByVal sender As Object, ByVal e As

System.EventArgs) Handles MnuClose.Click


RTB.Clear()
End Sub
Private Sub MnuCut_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MnuCut.Click
RTB.Cut()
End Sub
Private Sub MnuCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MnuCopy.Click
RTB.Copy()
End Sub
Private Sub MnuPaste_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MnuPaste.Click
RTB.Paste()
End Sub
Private Sub MnuExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuExit.Click
End
End Sub
End Class

PROPERTY WINDOW

Properties
Controls
Name

Text

Text Box

TextBox1

Label

Label1

Save As

Button

ButSave

Save

MnuNew

New

MnuSave

Save

MnuClose

Close

MnuPaste

Paste

MnuCut

Cut

MnuCopy

Copy

MnuExit

Exit

Menu Strip

RichTextBox

RTB

RESULT:
Thus the above program has been executed and verified

Ex.No:5

CALCULATOR

AIM
Write a program in VB.Net to implement a calculator with memory and
recall operation

PROCEDURE

1.

Open Microsoft Visual studio and create a new windows application

2.

Design form creation

3.

Edit the code in the event of all controls.

4. Run the application

PROGRAM
Public Class Form1
Dim a, m As Integer
Dim op As Char
Private Sub ButCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButCancel.Click
Text1.Clear()
End Sub
Private Sub ButMem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButMem.Click
m = Text1.Text
Text1.Clear()
End Sub
Private Sub ButRecall_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButRecall.Click
Text1.Text = m
End Sub
Private Sub ButOne_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButOne.Click
Text1.AppendText("1")
End Sub
Private Sub ButTwo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButTwo.Click
tAText1.AppendText("2")
End Sub

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


System.EventArgs) Handles ButThree.Click
Text1.AppendText("3")
End Sub
Private Sub ButFour_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButFour.Click
Text1.AppendText("4")
End Sub
Private Sub ButFive_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButFive.Click
Text1.AppendText("5")
End Sub
Private Sub ButSix_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButSix.Click
Text1.AppendText("6")
End Sub
Private Sub ButSeven_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButSeven.Click
Text1.AppendText("7")
End Sub
Private Sub ButEight_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButEight.Click
Text1.AppendText("8")
End Sub
Private Sub ButNine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButNine.Click

Text1.AppendText("9")
End Sub
Private Sub ButZero_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButZero.Click
Text1.AppendText("0")
End Sub
Private Sub ButPlus_Click(ByVal sender As System.Object, ByVal e As
System.Evenrgs) Handles ButPlus.Click
a = Val(Text1.Text)
op = "+"
Text1.Clear()
End Sub
Private Sub ButMinus_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButMinus.Click
a = Val(Text1.Text)
op = "-"
Text1.Clear()
End Sub
Private Sub ButMul_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButMul.Click
a = Val(Text1.Text)
op = "*"
Text1.Clear()
End Sub
Private Sub ButDiv_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButDiv.Click

a = Val(Text1.Text)
op = "/"
Text1.Clear()
End Sub
Private Sub ButEqual_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButEqual.Click
Select Case op
Case "+"

Text1.Text = a + Val(Text1.Text)

Case "-"

Text1.Text = a - Val(Text1.Text)

Case "*"

Text1.Text = a * Val(Text1.Text)

Case "/"

Text1.Text = a / Val(Text1.Text)

Case "%" Text1.Text = a / 100


End Select
End Sub
Private Sub ButPer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButPer.Click
a = Val(Text1.Text)
op = "%"
Text1.Clear()
End Sub
End Class

PROPERTY WINDOW

Properties
Controls
Name

Text

Label

Label1

CALCULATOR

Text box

Text1

Button

ButOne

Button

ButTwo

Button

ButThree

Button

ButFour

Button

ButFive

Button

ButSix

Button

ButSeven

Button

ButEight

Button

ButNine

Button

ButZero

Button

ButMem

Button

ButCancel

Button

ButRecall

Button

ButPlus

Button

ButMinus

Button

ButMul

Button

ButDiv

Button

ButEqual

Button

ButPer

RESULT:
Thus

the

above

program

has

been

executed

and

verified.

EX.NO:6

Display Day, Month, Year from Calendar Control

AIM
Develop a form in VB.NET to pick a date form calender
control and display the Day,month,year in separate text boxes.
PROCEDURE
1. Open Microsoft Visual studio and create a new windows application.
2. Design a form as Shown below.
3. Edit the following code in the Lad event of Form 1
TextBox 1.Text = DateTimePicker1.Value.Day
TextBox 2.Text = DateTimepicker1.Value.Month
TextBox3.Text = DateTimePicker1.Value.Year
4. Edit the above code also in the ValueChanged event of DateTimePicker1
5. Run the application.

Public Class Form1


Private Sub ButDisplay_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButDisplay.Click
TextBox1.Text = DateTimePicker1.Value.Day
TextBox2.Text = DateTimePicker1.Value.Month
TextBox3.Text = DateTimePicker1.Value.Year
End Sub
Private Sub ButClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButClose.Click
End
End Sub
End Class

PROPERTY WINDOW

Properties
Controls
Name

Text

Label

Label1

Display Day, Month and Yea of The Given Dater

DateTimePicker

DateTimePicker1

Text box

TextBox1

Text box

TextBox2

Text box

TextBox3

Button

ButDisplay

Display

Button

ButClose

Close

RESULT:
Thus the above program has been executed and verified.

Ex.No:7

QUIZ PROGRAM

AIM
To Develop a VB.NET application to perform timer based
quiz of 5 questions.
PROCEDURE
1. Open Microsoft Visual studio and create a new windows application.
2. Design a Form
3. Edit the code in the event of all controls
4. Set the interval property of the timer by 1000 or 2000.
5. Run the application.

PROGRAM
Public Class Form1
Dim quest(4, 3), ans(4, 1) As String
Dim i As Integer = -1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
handles MyBase.Load
quest(0, 0) = "In which year india won the cricket world cup?"
quest(0, 1) = "1973"
quest(0, 2) = "1983"
quest(0, 3) = "1986"
quest(1, 0) = "Scanner is a ______________ device"
quest(1, 1) = "Input"
quest(1, 2) = "Output"
quest(1, 3) = "i/o"
quest(2, 0) = "Which one of the following is a broweser?"
quest(2, 1) = "visual Basic"
quest(2, 2) = "Java"
quest(2, 3) = "Internet Explorer"
quest(3, 0) = "__________is the desciples of Jesus came to india?"
quest(3, 1) = "Thomas"
quest(3, 2) = "Andrew"
quest(3, 3) = "Philip"
quest(4, 0) = "Sunami hit india on_______________________"
quest(4, 1) = "24-12-2006"
quest(4, 2) = "26-12-2004"
quest(4, 3) = "26-12-2006"

ans(0, 0) = "1983"
ans(1, 0) = "Input"
ans(2, 0) = "Internet Explorer"
ans(3, 0) = "Thomas"
ans(4, 0) = "26-12-2004"
Timer1.Enabled = True
Button1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
i=i+1
If (i = 5) Then
Timer1.Enabled = False
Button1.Enabled = True
Else
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
TextBox1.Text = quest(i, 0)
RadioButton1.Text = quest(i, 1)
RadioButton2.Text = quest(i, 2)
RadioButton3.Text = quest(i, 3)
End If
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton1.CheckedChanged

ans(i, 1) = RadioButton1.Text
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton2.CheckedChanged
ans(i, 1) = RadioButton2.Text
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton3.CheckedChanged
ans(i, 1) = RadioButton3.Text
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim j As Integer
Dim count As Integer = 0
For j = 0 To 4
If (ans(j, 0) = ans(j, 1)) Then
count += 1
End If
Next
MsgBox("You have Scored " & count & " marks")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End
End Sub
End Class

PROPERTY WINDOW

Properties
Controls
Name

Text

Label

Label1

QUIZ PROGRAM

Label

Label2

Question

Text Box

TextBox1

Group Box

GroupBox1

Answer

Radio Button

RadioButton1

Option1

Radio Button

RadioButton2

Option2

Radio Button

RadioButton3

Option3

Button

Button1

Result

Button

Button2

Close

Timer

Timer1

RESULT;
Thus the above program has been executed and verified.

Interval

1000

Ex.No:8

OPERATIONS ON FILE and DIRECTORY LIST BOX

AIM
Develop a VB.NET application using the File and directory
controls to implement a common dialog box.
PROCEDURE
1. Open Microsoft Visual studio create a new windows application.
2. Design a Form
3. Edit the following code in the Click event of the Button1
If RadioButton 1.Checked Then
FolderBrowserDialog 1.ShownDialog()
TextBox1.Text = FolderBrowserDialog1.SelectedPath
Else
OpenFileDialog1.ShownDialog()
TextBox2.Text = OpenFileDialog1.FileName
End If
4.Run the application.

PROGRAM
Public Class Form1
Private Sub ButOk_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ButOk.Click
If RadioButton1.Checked Then
FolderBrowserDialog1.ShowDialog()
TextBox1.Text = FolderBrowserDialog1.SelectedPath
Else
OpenFileDialog1.ShowDialog()
TextBox2.Text = OpenFileDialog1.FileName
End If
End Sub
End Class

PROPERTY WINDOW

Properties
Controls
Name

Text

GroupBox

GroupBox1

Select the Option

Radio Button

RadioButton1

Folder Name

Radio Button

RadioButton2

File Open

Label

Label1

Selected Folder

Label

Label2

Selected File

Text Box

TextBox1

Text Box

TextBox2

Button

ButOk

Ok

RESULT:
Thus the above program has been executed and verified.

Ex.No:9

STORE STUDENT DETAILS USING ADO.NET

AIM
To Develop a database application to details of students
using ADO.NET.
PROCEDURE
1. Create a table stud in a Sql server database student
(using SQL Qurey Analyzer)
Create database student
Use student
Create table stud (regno varchar(10), sname varchar(15),
dept varchar(10))
2. Open Microsoft Visual studio and create a new windows application
3. Design a Form as shown below
4. Edit the following line at the top of the coding before any other code
Imports System.Data.SqlClient
5 . Edit tje following code inside the class Form1 before all the sub funtions.
Dim con As SqlConnection
Dim Com as SqlCommand
6. Edit the following code in the load event of Form1
con = New SqlConnection
con = New SqlCommand
con.connectionString = "intial catlog=student;user id=sa; pwd="
con.Open()
con.Connection = con

7. Edit the following code in the Click event of the Button1


If TextBox1.Text = "" Or Text Box2.Text = " " Or
Text Box3.Text = " "Then
MsgBox("please fill all the details")
Exit Sub
End If
com.commandText = "insert into stud values('" &
TextBox1.Text &
"',"' & TextBox2.Text & "',"' & TextBox3.Text & '')"
com.ExecuteNonQuery()
MsgBOX("1 record is stored successfully")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
8. Run the application.

PROGRAM:
Imports System.Data.Odbc
Public Class Form1
Dim con As OdbcConnection
Dim com As OdbcCommand
Private Sub ButStore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ButStore.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Pleas fill the details")
Exit Sub
End If
com.CommandText = "insert into tam_db1 values('" & TextBox1.Text & "','" &
TextBox2.Text & "','" & TextBox3.Text & "')"
com.ExecuteNonQuery()
MsgBox(" 1 record is stored successfully")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
con = New OdbcConnection
com = New OdbcCommand
con.ConnectionString = "DSN=s;initial catalog=tam_db1;user id=;pwd="
con.Open()
com.Connection = con

End Sub
Private Sub ButClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButClose.Click
End
End Sub
End Class

Properties
Controls
Name

Text

Label

Label1

Student Database

Label

Label2

Name

Label

Label3

Roll No

Label

Label4

Dept

Text Box

Text Box1

Text Box

TextBox2

Text Box

TextBox3

Button

ButStore

Store

Button

ButClose

Close

RESULT:
Thus the above program has been executed and verified.

Ex.No:10.

USING ADO.NET DEVELOPS A DATABASE WITH INSERT, DELETE AND UPDATE


OPERATIONS

AIM
To Develop a database application using ADO.NET with insert,
delete and Update operations.
PROCEDURE:
1. Create a table stud in Sql server database student
(using SQL Qurey Analyzer)
Create database student
Use student
Create table stud(regno varchar(10), sname varchar(15),
dept varchar(10))
Insert into stud values('115526', 'Robert', 'Civil')
2. Open Microsoft visual studio and create a new windows application.
3. Design a Form as shown below.
4. Edit the following line at the top of the coding before any other code
Imports System.Data..SqlClient
5. Edit the following code inside the class form1 before all the sub functions
Dim con As SqlConnections
Dim com As SqlCommand
Dim rd As SqlDataReader
6. Edit the following code in the Load event of Form1
con = New SqlConnction
con = New SqlCommand
con.ConnectionString = "intial catalog=student;user id=sa; pwd="
con.Open()

com.connection = con
7. Enter the following code in the CheckedChanged event of RadioButton1
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
ComboBox1.Visible = False
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
8. Enter the following code in the CheckedChanged event of RadioButton2
ComboBox1.Items.Clear()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = True
ComboBox1.Visible = True
com.commandText = "select * form stud"
rd = com.ExecuteReader
While rd.Read
ComboBox1.Items.Add(rd.GetString(0))
End While
rd.Close()
9. Edit the following code in the SelectedindexChanged event of ComboBox1
com.CommandText = "select * form stud where regno='"&
ComboBox1.SelctedITem & "'"
rd = com.ExecuteReader
If rd.Read Then

TextBox2.Text = rd.GetString(1)
TextBox3.Text = rd.GetString(2)
End If
rd.Close()
10. Edit the following code in the Click event of the Button1
If TextBox1.Text = "" Or TextBox2.Text = ""Or
TextBox3.Text = "" Then
MsgBox("please fill all the details")
Exit Sub
End If
com.CommandText = "insert into stud values('" &
TextBox1.Text & '",'" &
TextBox2.Text & '", '" & TextBox3.Text & '")"
com.ExecuteNonQurey()
MsgBox(" record inserted")
11. Edit the following code in the Click event of the Button2
com.CommandText = "deleted from stud where regno='" &
ComboBox1.SelectedItem & "'"
com.ExecuteNonQurey()
ComboBox1.Items.Remove(ComboBox1.SelectedItem)
TextBox2.Clear()
TextBox3.Clear()
MsgBox("Record deleted")
12. Edit the following code in the Click event of the Button3
com.CommandText = "update stud set sname=" &
TextBox2.Text &

"',dept='" & TextBox3.Text &"' where regno='" &


ComboBox1.SelectedItem &"'"
com.ExecuteNonQurey()
MsgBox("Record updated")
13. Run the application.

PROGRAM
Imports System.Data.Odbc
Public Class Form1
Dim con As OdbcConnection
Dim com As OdbcCommand
Dim rd As OdbcDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con = New OdbcConnection
com = New OdbcCommand
con.ConnectionString = "DSN=s;intial catalog=tam_db1;user id=;pwd="
con.Open()
com.Connection = con
End Sub
Private Sub ButInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButInsert.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Please fill all the details")
Exit Sub
nged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioInsert.CheckedChanged
TextBox1.Clear()End If
com.CommandText = "insert into tam_db1 values (' " & TextBox1.Text &
" ',' " & TextBox2.Text & " ',' " & TextBox3.Text & " ') "
com.ExecuteNonQuery()

MsgBox("1 Record is inserted")


End Sub
Private Sub ButDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButDelete.Click
Com.CommandText = "delete from tam_db1 where rollno=" &
ComboRollNo.SelectedItem & ""
com.ExecuteNonQuery()
ComboRollNo.Items.Remove(ComboRollNo.SelectedItem)
TextBox1.Clear()
TextBox3.Clear()
MsgBox("Record is deleted")
End Sub
Private Sub ComboRollNo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ComboRollNo.SelectedIndexChanged
com.CommandText = "select * from tam_db1 where rollno=" &
ComboRollNo.SelectedItem & ""
rd = com.ExecuteReader
If rd.Read Then
TextBox1.Text = rd.GetString(0)
TextBox3.Text = rd.GetString(2)
End If
rd.Close()
End Sub
Private Sub RadioInsert_CheckedCha
TextBox2.Clear()
TextBox3.Clear()

ComboRollNo.Visible = False
ButInsert.Enabled = True
ButDelete.Enabled = False
ButUpdate.Enabled = False
End Sub
Private Sub RadioView_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioView.CheckedChanged
ComboRollNo.Items.Clear()
ButInsert.Enabled = False
ButDelete.Enabled = True
ButUpdate.Enabled = True
ComboRollNo.Visible = True
com.CommandText = "select * from tam_db1"
rd = com.ExecuteReader
While rd.Read
ComboRollNo.Items.Add(rd.GetString(1))
End While
rd.Close()
End Sub
Private Sub ButUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButUpdate.Click

End Classcom.CommandText = "Update tam_db1 set name='" & TextBox1.Text & "',dept='" &
TextBox3.Text & "' where rollno=" & ComboRollNo.SelectedItem & ""
com.ExecuteNonQuery()
MsgBox("Record is updated")

End Sub
Private Sub ButClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ButClose.Click
End
End Sub

Properties
Controls
Name

Text

Label

Label1

Perform Insert, Delete and Update Operation in


Database using ADO.Net

Label

Label2

Student Name

Label

Label3

Register No

Label

Label4

Department

Text Box

Text Box1

Text Box

TextBox2

Text Box

TextBox3

Button

ButInsert

Insert

Button

ButUpdate

Update

Button

ButDelete

Delete

Button

ButClose

Close

Radio Button

RadioInsert

INSERT

Radio Button

RadioView

VIEW

Group Box

GroupBox1

Select your Choice

RESULT:
Thus the above program has been executed and verified.

Ex.No :11

DISPLAY THE RECORDS IN A TABLE USING DATA GRID IN VB.NET

AIM
ToDevelop a VB.NET application using DataGrid to display the records
in a table.
PROCEDURE
1. create a table stud in a sql server database student
(using SQL Query Analyzer)
Create database student
Use student
Create table stud(regno varchar(10),sname varchar(15),
dept varchar(10))
Insert into stud values('115526','Robert','Civil')
Insert into stud values('114726','Prince','ECE')

2. Create DSN for the Student database.


open start?settings?control panel?Adminstrative Tools?Data soucres(ODBC)

3. Click ADD? SQL server?Finish.Enter a name for the DSN and enter the name
of the server and click Next.

4. Click the radiobutton With SQL server authentication.enter the Loginid and
password and click Next.

5. Change the default Database to student and click Next?Finish?


Test Data Source....?OK ? OK

6. Close the ODBC window and Open Microsoft Visual studio and
create a new Windows application

7. Drag the DataGrid controll from the ToolBox into the from 1.
(if the datagrid control not exist then right
click on any data control,select choose items....option.

Tick the datagrid controls.

8. In the data menu select Add New Data Source..,database,next,new connection.....

9. Change the data source into Mircosoft ODBC Data source and select the Data source name.
Enter the username and password and click test connection OK, OK,OK, Next

10. Tick the reguired option and click finish?ok.

11. In the Data menu select Show Data Soucres option Drag the
table name into DataGrid control.

12. Run the application

PROGRAM:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
'TODO: This line of code loads data into the 'MasterDataSet.student' table. You can move, or
remove it, as needed.
Me.StudentTableAdapter.Fill(Me.MasterDataSet.student)
End Sub
End Class

RESULT:
Thus the above program has been executed and verified

Ex No:12

CREATING SIMPLE WEB PAGE USING ASP.NET

AIM
Create a simple ASP.NET page to output Text with a from ,
two HTML button and an HTML <span> element.Create an
event procedurce for the button
1. Open Microsoft Visual studio and create a new web site
2. Drag the requried controls from the Tool box
3. Click the source tab and edit the requried code
4. Run the page using Internet explorer.
PROGRAM:

<%@Page Language ="VB" AutoEventWireup="false"


CodeFile ="Default.aspx .vb" Inherits ="Default "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml 1/DTD/xhtml 1transitional.dtd">
<script runat="serv
Sub Button _Click (By Val S As Object ,ByVal E As Event Args)
Response.Write("Your Name is "& Text1.Value &".
Your password is "& password1.Value)
End Sub

</script>
<html xmlns ="http://www.w3.org /1999/xhtml">
<head runat="server">
<title> Untitled Page</title>
</head>
<body>
<from runat="server">
<span>
Username:

<input id="Text 1"type="text runat="server"/></br/>


Password:
<input id ="password 1"type="password"runat="server"
style="width:149px" />

<input type="sumbit"id="Button 1"value="Click"


onserverclick ="Button_Click" runat="server" />
</span>
</form>
</body>
</html>

RESULT:
Thus the above program has been executed and verified

Ex.No:13

Reserving Room in a Hotel

AIM
To Create a web controls to a pane with three different controls to the
ASP.NET page for reserving rooms in the hotel .
(Three controls are button ,label and a drop-down list control)
PROCEDURE:
1. Open Microsoft Visual studio and create a new web site
2. Drag the required controls from the tool box
3. Click the source tab and edit the required code
4. Run the page using internet explorer.

PROGRAM:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal S As Object,ByVal E As EventArgs)Handles Me.Load
If Not IsPostBack Then
Dim i As Integer
For i = 1 To 10
DropDownList1.Items.Add(i)
Next
End If
End Sub
Sub Reserve_Click(ByVal S As Object,ByVal E As EventArgs)
Label1.Text="The Room Reserved For You is "& DropDownList1.Text
If DropDownList1.Items.Count=0 Then
Button1.Enabled=False
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
</head>
<body>

Untitled Page

</title>

<form id="form1" runat="server">


<div>
<span style="font-family: Georgia"><strong>Reserving Room in Hotel
<br /> </strong> </span>

<br /> <br />

<span style="font-family: Georgia">


<strong>

No </strong> :

<strong>

<br />
Room

</strong>

</span>

<asp:DropDownList ID="DropDownList1" runat="server" Width="293px"


Font-Bold="True" Font-Names="Georgia" Font-Size="12pt">
</asp:DropDownList>

<br /> <br />

<br /> <br />

<asp:Button ID = "Button1" runat="server" Text="Reserve Room" OnClick="Reserve_Click"


Font-Bold="True" Font-Names="Georgia" />
<br /> <br />

<br />

<asp:Label ID="Label1" runat="server" Width="321px" Font-Bold="True" Font-Names="Georgia"


Font-Size="12pt"></asp:Label>
<br /> <br />
</div>
</html>

<br />

</form>

</body>

RESULT:
Thus the above program has been executed and verified.

EX:14

ACCESSING SQL SERVER DATABASE USING ADO.NET

AIM
To create an application for accessing a SQL server database by using
ADO.NET by connecting to the database call stored procedure.you
Then display the data in a repeater control.

PROCDURE
1. create a table Ex1 in the database MGPT in sql server
2. open Microsoft visual studio and create a new web site
3. Drag the required controls from the tool box
4. click the source tab and edit the required
5.Run the application

PROGRAM

<%@Page Language =VB AutoEventWireup=false


CodeFile =Default3.aspx.vbInherits=Defult3%>
<%@Import Name space=System.Data.sqlClient%>
<!DOCTYPE html PUBLIC-//W3C//DTD XHTML 1.0
Transitional..//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1Transitional.dtd>
<script runat=server>
Dim Conn As New sqlConnection
Dim Comm As New Sql command
Sub Page_Load(By VAL S As Object,By Val E As Event Args)
Handles Me.Load
Conn.ConnectionString=initial catalog=MGPT;user
Id=sa;pwd=
Conn.Open()
Comm.Connection = Conn
If Not Is PostBack Then
Comm.CommandText =Select distinct(LType) from Ex
DropDownList1.DataSource = Comm.ExecuteReader
DropDownList1.DataTextfield= LType
DropDwonList1.DataBind()

End If
End Sub
Sub Show_Click(By Val S As Object,ByVal E As Event Args)
Comm.CommandText=select*from Ex1 where
LType=@Type
Comm.Parameters.AddWidthValue(@Type,
DropDownList1.Text)
Repeater1.DataSource=Comm.ExecuteReader
Repeater1.DataBind()
End Sub
</script>
</html xmlns=http://www.w3.org/1999/Xhtml>
<head runat=server>
</title>Untitled Page</title>
</head>
<body>
<from id =from1runat=server>
<div>
Staff&nbsp;Type :&nbsp;<asp:DropDownList
ID=DropDownList1runat=server
Width=173px>
</asp:DropDownList>&nsbp;<asp:Button ID=Button1
Runat =serverText=ShowOnClick=Show_Click/>
<br/><br/>
<asp:Repeater ID=Repeater1runat=server>
<HeaderTemplate>

<front color=maroon>
<h2>Names</h2>
</front>
</HeaderTemplate>
<ItemTemplate>
<front color=aquaface=Arial>
<%#Container.DataItem(LName)%>
</front>
</ItemTemplate>
<SeparatorTemplate>
</asp:Repeater>
</div>
</from>
</body>
</html>

RESULT:
Thus the above program has been executed and verified.

Você também pode gostar