INDEX
S Topics Page Teacher
NO. no. sign.
1. Program to show the use of 4-5
inputbox and messagebox to
display the name
2. Program to accept a number 6-8
an check whether it is prime
or not
3. Progrom to show largest in 9-10
three numbers using call by
value
4. Program to print Fibonacci 11
series
5. Program to print factorial 12-13
series
6. Program To Find the Sum of 14-15
Array elements
7. Program to show arraylist and 16-19
its operations
1
8. Program to swap 2 numbers 20-21
using call by reference method.
9. Program to find the length of the 22-23
string and check whether it is
palindrome or not
10. Program to illustrate Calculator 24-27
11. Program to illustrate the class 28-30
12. Program on overloaded 31-32
methods - Polymorphism
13. Program on Hierarchical 33-34
Inheritance
14. Program to show 35-36
Implementation of Multi-level
Inheritance
15. Program to show 37-38
Implementation of Multiple
Inheritance using Interface
2
16. Write a program to transfer 39-41
items from listbox to
combobox and vice versa
17. Program to display current date 42-43
& time
18. Program on illustration of 44-46
menustrip control
19. Program on illustration of 47-51
listview control in vb.net
20. Program on Exceptional 52-54
Handling
21. Program of accessing database 55
using datagrid
22. Program to perform database 56-61
operations(add,delete,update)
using ADO.net
3
1. Program to show the use of inputbox and
messagebox to display the name
CODING :
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As String
a = TextBox1.Text
MessageBox.Show("HELLO " & a & " WELCOME TO VB.NET")
End Sub
End Class
4
OUTPUT :
5
2. Program to accept a number an check whether it is
prime or not
CODING:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i, j As Integer
Dim t As Boolean i
= TextBox1.Text t =
True
For j = 2 To (i - 1)
If i Mod j = 0 Then
t = False
Exit For
End If
Next j
If t Then
MsgBox(i & " is prime number")
Else
MsgBox(i & " is not a prime number")
End If
End Sub
End Class
6
Output :
7
3. Progrom to show largest in three numbers using
call by value
8
CODING :
Module largest
Public Function large(ByVal a As Integer, b As Integer, c As Integer)
Dim max As Integer
If a > b And a > c Then
max = a ElseIf b > c
Then max = b
Else max = c
End If
Return max
End Function
End Module
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x, y, z As Integer
x = TextBox1.Text y =
TextBox2.Text z =
TextBox3.Text
Label4.Text = "LARGEST IS " & large(x, y, z)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End
9
End Sub
End Class
OUTPUT :
4. Program to print Fibonacci series
Module Module1
Sub Main()
'to print fibonacci series
Dim f1, f2, f, cnt As Integer
Dim n As Integer
cnt = 1 f1 = 0
f2 = 1
Console.WriteLine("Enter a number")
n = Console.ReadLine()
Console.WriteLine("Fibonacci Series are as follows......")
Console.WriteLine(f1)
Console.WriteLine(f2)
While (cnt <= n) f =
f1 + f2
10
Console.WriteLine(f)
f1 = f2 f2 = f
cnt += 1
End While
Console.ReadKey()
End Sub
End Module
11
5. Program to print factorial series
Public Class Form1
'Factorial using function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim n As Integer n = CInt(TextBox1.Text)
Label2.Text = "Factorial of " & n & "is" & fact(n)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End
End Sub
End Class
Module Factorial
Public Function fact(ByVal x As Integer) As Long
Dim i As Integer = 1
Dim f As Integer = 1
Do While (i <= x)
f *= i i += 1
Loop
Return f
End Function
End Module
12
6. Program To Find the Sum of Array elements
13
CODING:
Module Module1
Sub Main()
Dim n(5) As Integer
Dim s As Integer = 0
Console.WriteLine("Enter 5 Elements")
For i = 1 To 5
n(i) = CInt(Console.ReadLine())
Next i
Console.WriteLine("Array Elements are")
For i = 1 To 5
Console.WriteLine(n(i))
s = s + n(i)
Next i
Console.WriteLine("Sum of array elements=" & s)
Console.ReadLine()
End Sub
End Module
OUTPUT:
14
7. Program to show arraylist and its operations
CODING:
Public Class Form1
Dim A As New ArrayList
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
15
A.Insert(3, "BJMC")
TextBox1.Clear()
MsgBox("Item inserted successfully", , "Inserting an item ")
For i = 0 To A.Count - 1
TextBox1.Text = TextBox1.Text + " " + A.Item(i) + vbCrLf
Next
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
A.RemoveAt(2)
TextBox1.Clear()
MsgBox("Item removed successfully",,)
For i = 0 To A.Count - 1
TextBox1.Text = TextBox1.Text + " " + A.Item(i) + vbCrLf
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
A.Remove("BCA")
TextBox1.Clear()
MsgBox("Deleted successfully",, "Deletion operation on Arraylist")
For i = 0 To A.Count - 1
TextBox1.Text = TextBox1.Text + " " + A.Item(i) + vbCrLf
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
A.Add("BCA")
A.Add("MCA") A.Add("BBA")
A.Add("MBA")
MsgBox("Items added",, "Arraylist")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox("Number of Items added is " & A.Count,, "Displaying Arraylist")
TextBox1.Clear()
For i = 0 To A.Count - 1
TextBox1.Text = TextBox1.Text + " " + A.Item(i) + vbCrLf
Next
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
A.Sort()
TextBox1.Clear()
MsgBox("Number of Items added is " & A.Count,, "Displaying Sorted Arraylist")
For i = 0 To A.Count - 1
TextBox1.Text = TextBox1.Text + " " + A.Item(i) + vbCrLf
Next
End Sub
End Class
16
17
18
19
8. Program to swap 2 numbers using call by reference method
CODING :
Module funcswap
Public Sub swap(ByRef x As Integer, ByRef y As Integer)
Dim t As Integer
t=x x=y
y=t
End Sub
End Module
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim a, b As Integer
a = CInt(TextBox1.Text)
b = CInt(TextBox2.Text)
swap(a, b)
TextBox3.Text = a
TextBox4.Text = b
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
End
End Sub
End Class
20
OUTPUT:
9. Program to find the length of the string and check
whether it is palindrome or not
21
CODING :
Public Class Form2
Dim st, rev As String
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
End
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click st =
TextBox1.Text rev =
Trim(StrReverse(st))
Label2.Text = rev
If String.Compare(st, rev, True) = 0 Then
MsgBox(st & " Is a Palindrome", , "To Check string")
Else
MsgBox(st & " Not a Palindrome", , "To Check string")
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
st = TextBox1.Text
MsgBox("Length of the string is " & st & " is " & Len(st), , "Find Length")
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs)
End Sub
End Class
22
OUTPUT:
10. Program to illustrate Calculator
23
CODING :
Public Class Form1
Dim temp1, flag, result As Integer
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(2)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(1)
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles
Button10.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(0)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(3)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(4)
End Sub
24
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(5)
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles
Button6.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(6)
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles
Button7.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(7)
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles
Button8.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(8)
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles
Button9.Click
TextBox1.Text = Convert.ToString(TextBox1.Text) + Convert.ToString(9)
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
TextBox1.Text = " "
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
temp1 = TextBox1.Text
TextBox1.Text = " "
flag = 4
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
If flag = 0 Then
result = temp1 + TextBox1.Text
TextBox1.Text = " "
TextBox1.Text = result
ElseIf flag = 1 Then
result = temp1 - TextBox1.Text
TextBox1.Text = " "
TextBox1.Text = result
ElseIf flag = 2 Then
25
result = temp1 / TextBox1.Text
TextBox1.Text = " "
TextBox1.Text = result
Else
result = temp1 * TextBox1.Text
TextBox1.Text = " "
TextBox1.Text = result
End If
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
temp1 = TextBox1.Text
TextBox1.Text = " "
flag = 3
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
temp1 = TextBox1.Text
TextBox1.Text = " "
flag = 0
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
temp1 = TextBox1.Text
TextBox1.Text = " "
flag = 1
End Sub
End Class
26
OUTPUT:
27
11. Program to illustrate the class
CODING :
Public Class Telephonebill
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim p As Long = CLng(TextBox1.Text)
Dim s As String = TextBox2.Text
Dim c As Integer = CInt(TextBox3.Text)
Dim a As Double
Dim ob1 As New telcall(p, s, c)
a = ob1.compute()
Label6.Text = a
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
28
End
End Sub
End Class
Module Modcls
Public Class telcall
Dim phno As Long
Dim name As String
Dim n As Integer
Dim amt As Double
Public Sub New(ByVal p As Long, ByVal s As String, ByVal c As Integer)
phno = p name = s n=c amt = 0.0
End Sub
Public Function compute() As Double
If (n <= 100) Then
amt = 500
ElseIf (n <= 200) Then
amt = (n - 100) * 1.0 + 500
ElseIf (n <= 300) Then
amt = 100 * 1.0 + (n - 200) * 1.2 + 500
Else
amt = 100 * 1.0 + 100 * 1.2 + (n - 300) * 1.5 + 500
End If
Return amt
End Function
End Class End
Module
29
OUTPUT:
30
12. Program on overloaded methods -
Polymorphism
CODING:
Public Class test
Sub area(ByVal a As Integer)
Dim sqarea As Integer = 0
sqarea = a * a
Form1.Label1.Text = "Area of a Square is " & sqarea
End Sub
Sub area(ByVal l As Integer, ByVal b As Integer)
Dim recarea As Integer = 0
recarea = l * b
Form1.Label2.Text = "Area of a Rectange is " & recarea
End Sub
Sub area(ByVal r As Double)
Dim cirarea As Double = 0
cirarea = 3.14 * r * r
Form1.Label3.Text = "Area of a Circle is " & cirarea
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ob1 As New test()
Label1.Visible = True
31
Label2.Visible = True
Label3.Visible = True
ob1.area(5) ob1.area(6,
5) ob1.area(2.5)
End Sub
End Class
32
13. Program on Hierarchical Inheritance
Module module1
'Implementation of Hierarchical Inheritance
Public Class number
Dim num As Integer
Public Sub getnum()
Console.Write("Enter a number : ")
num = CInt(Console.ReadLine())
End Sub
Public Function retnum() As Integer
Return num
End Function
End Class
Public Class square
Inherits number
Public sqr, n1 As Integer
Public Function sqrnum(ByRef n1 As Integer) As Integer
sqr = n1 * n1 Return sqr
End Function
End Class
Public Class cube
Inherits number
Public cub, n2 As Double
Public Function cubnumber(ByRef n2 As Double) As Double
cub = n2 * n2 * n2
Return cub
End Function
End Class
Sub main()
Dim sobj As New square
Dim cuobj As New cube
Dim a As Integer
sobj.getnum() a=
sobj.retnum()
Console.WriteLine("Square of " & a & " is " & sobj.sqrnum(a))
Console.WriteLine(vbCrLf)
cuobj.getnum() a=
cuobj.retnum()
Console.WriteLine("Cube of " & a & " is " & cuobj.cubnumber(a))
Console.ReadKey()
End Sub
33
End Module
34
14. Program to show Implementation of Multi-level
Inheritance
'Implementation of Multi-level Inheritance
Public Class person
Public Name As String
Public Age As Integer
Public Sub New(ByVal Name As String, ByVal Age As Integer)
Me.Name = Name
Me.Age = Age
End Sub
End Class
Class Player
Inherits person
Public Sport As String
Public Team As String
Public Sub New(ByVal Name As String, ByVal Age As Integer,
ByVal Sport As String, ByVal Team As String)
MyBase.New(Name, Age)
Me.Team = Team
Me.Sport = Sport
End Sub
End Class
Class BasketPlayer
Inherits Player
Public PointsPerGame As Double
Public Rebounds As Double
Public Sub New(ByVal Name As String, ByVal Age As Integer,
ByVal Sport As String, ByVal Team As String, ByVal Points As Double, ByVal
Rebounds As Double)
MyBase.New(Name, Age, Sport, Team)
Me.PointsPerGame = Points
Me.Rebounds = Rebounds
End Sub
Public Sub Show()
Console.WriteLine("Multi-level Inheritance")
Console.WriteLine("")
Console.WriteLine("Player: " & Name)
Console.WriteLine("Age: " & Age)
Console.WriteLine("Sport: " & Sport)
Console.WriteLine("Team: " & Team)
Console.WriteLine("Points: " & PointsPerGame)
Console.WriteLine("Rebounds: " & Rebounds)
End Sub
End Class
Sub Main()
Dim p As New BasketPlayer("AA", 12, "Basketball", "Team", 25.5, 6.3)
p.Show() Console.ReadKey()
35
End Sub
36
15. Program to show Implementation of Multiple
Inheritance using Interface
Module Module2
'Implementation of Multiple Inheritance using Interface
Interface test
Function marks() As Integer
End Interface
Interface sports
Function grade_show(ByVal avg As Single) As Char
End Interface
Class result
Implements test
Implements sports
Public Function marks() As Integer Implements test.marks
Dim m1, m2, m3, m4, m5 As Integer
Dim avg As Single
Console.WriteLine("Enter the marks of five subjects")
m1 = CInt(Console.ReadLine()) m2 =
CInt(Console.ReadLine()) m3 =
CInt(Console.ReadLine()) m4 =
CInt(Console.ReadLine()) m5 =
CInt(Console.ReadLine()) avg = (m1 + m2 + m3 + m4 +
m5) / 5
Return avg
End Function
Public Function grade_show(ByVal avg As Single) As Char Implements sports.grade_show
Dim grade As Char
If avg >= 80 Then
grade = "A" ElseIf
avg >= 60 Then
grade = "B" ElseIf
avg >= 50 Then
grade = "C" Else
grade = "D"
End If
Return grade
End Function
End Class
Sub main()
Dim obj As New result()
Dim av As Single
Console.WriteLine("Implementation of Multiple Inheritance using Interface")
av = obj.marks() Console.WriteLine()
Console.WriteLine("Average Marks is " & av)
Console.WriteLine()
Console.WriteLine("Grade is " & obj.grade_show(av))
Console.ReadKey()
End Sub
End Module
37
38
16. Write a program to transfer items from listbox to
combobox and vice versa.
CODING:
Public Class Form1
Dim n As Integer
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ListBox1.SelectedIndexChanged
' MsgBox(ListBox1.SelectedItem)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
' MsgBox(ComboBox1.SelectedItem)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(ComboBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.Text)
End Sub
39
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ComboBox1.Items.Add(ListBox1.SelectedItem)
ComboBox1.Items.Remove(ComboBox1.Text)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
n = ListBox1.Items.Count
For i = 0 To n - 1
ListBox1.Items.Add(ComboBox1.Items(i))
Next
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim m As Integer m = ComboBox1.Items.Count
For i = 0 To n - 1
ComboBox1.Items.Add(ListBox1.Items(i))
Next
End Sub
End Class
OUTPUT:
40
41
17. Program to display current date & time
CODING :
Public Class digitalclk
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
End
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Label1.Text = System.DateTime.Today
Label2.Text = DateTime.Now.ToLongTimeString()
End Sub
End Class
OUTPUT:
42
18. Program on illustration of menustrip control
43
Public Class Form1
Dim t As String
Private Sub CUTToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
CUTToolStripMenuItem.Click
t = TextBox1.Text
TextBox1.Text = " "
End Sub
Private Sub COPYToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
COPYToolStripMenuItem.Click
t = TextBox1.Text
End Sub
Private Sub PASTERToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles PASTERToolStripMenuItem.Click
TextBox2.Text = t
End Sub
End Class
44
45
46
19. Program on illustration of listview control
CODING :
Public Class Form2
Dim arrproducts(4) As String
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs)
Handles RadioButton1.CheckedChanged
If RadioButton1.Enabled = True Then
ListView2.Visible = False
ListView3.Visible = False
ListView1.Visible = True
ListView1.View = View.List
End If
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs)
Handles RadioButton3.CheckedChanged
If RadioButton3.Enabled = True Then
ListView1.Visible = True
ListView3.Visible = False
ListView2.Visible = False
ListView1.View = View.Details
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs)
Handles RadioButton2.CheckedChanged
If RadioButton2.Enabled = True Then
47
ListView1.Visible = False
ListView3.Visible = False
ListView2.Visible = True
For i = 0 To arrproducts.Length - 1
ListView2.Items.Add(arrproducts(i)) 'Add Each Item Of Array
ListView2.Items(i).ImageIndex = i 'Align ImageList Images With Array
Items
Next
End If
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs)
Handles RadioButton4.CheckedChanged
Dim i As Integer
If RadioButton4.Enabled = True Then
ListView3.Clear()
ListView2.Visible = False
ListView1.Visible = False
ListView3.Visible = True
For i = 0 To arrproducts.Length - 1
ListView3.Items.Add(arrproducts(i)) 'Add Each Item Of Array
ListView3.Items(i).ImageIndex = i 'Align ImageList Images With Array
Items
Next
End If
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs)
Handles RadioButton5.CheckedChanged
If RadioButton5.Enabled = True Then
ListView2.Visible = False
ListView3.Visible = False
ListView1.Visible = True
ListView1.View = View.Tile
End If
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
arrproducts(0) = "Computer"
arrproducts(1) = "Mouse"
arrproducts(2) = "Printer" arrproducts(3)
= "Scanner"
End Sub
End Class
48
OUTPUT:
49
50
51
20. Program on Exceptional Handling
CODING:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a = 10, b = 0, q As Integer Try q = a / b
Catch ex As ArithmeticException
MsgBox("Division by zero",, "Arithmetic Exception")
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim a As Integer
a = CInt(InputBox("Enter your marks"))
Try
If (a > 100) Then
Throw New my1("Enter marks less than 100")
End If
Catch obj As my1
MsgBox(obj.Message,, "User-defined Exception")
End Try
End Sub
Public Class my1
Inherits Exception
Public Sub New(ByVal msg As String)
MyBase.New(msg)
End Sub
End Class
End Class
52
OUTPUT:
53
54
21. Program of accessing database using datagrid
OUTPUT:
55
22. Program to perform database
operations(add,delete,update) using ADO.net
Imports System.Data.OleDb
Public Class Form1
56
Public rno As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=F:\kiheat\New folder\clg.accdb")
con.Open()
Dim cmd As New OleDbCommand("insert into student values(" + TextBox1.Text +
",'" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "'," +
TextBox5.Text + ")", con) cmd.ExecuteNonQuery()
MsgBox("record added") con.Close() End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
End
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
flag()
rno = InputBox("Enter the rollno. to be deleted")
disp()
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=F:\kiheat\New folder\clg.accdb")
con.Open()
Dim cmd As New OleDbCommand("Delete from student where rollno=" + rno, con)
cmd.ExecuteNonQuery() MsgBox("Record DELETED") con.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
flag()
Dim fld, value As String
rno = InputBox("Enter the rollno to be updated")
disp()
fld = InputBox("Enter the fieldname to be updated")
value = InputBox("Enter new value")
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=F:\kiheat\New folder\clg.accdb")
con.Open()
Dim cmd As New OleDbCommand("update student set " + fld + "=" + value + "
where rollno =" + rno, con) cmd.ExecuteNonQuery() MsgBox("Record
updated") disp() con.Close() End Sub
Public Sub flag()
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
End Sub
Public Sub disp()
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=F:\kiheat\New folder\clg.accdb")
con.Open()
Dim cmd As New OleDbCommand("Select * from student where rollno= " + rno, con)
Dim dr As OleDbDataReader = cmd.ExecuteReader()
dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
TextBox4.Text = dr(3)
TextBox5.Text = dr(4)
End Sub
57
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ClgDataSet.student' table. You can move,
or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.ClgDataSet.student)
ListBox1.Enabled = False
End Sub
End Class
OUTPUTS :
ADDING RECORD INTO STUDENT TABLE
58
DELETING RECORD FROM STUDENT TABLE
59
60
UPDATING RECORD IN A STUDENT TABLE
61
62