0% found this document useful (0 votes)
43 views64 pages

Visual Basics and Oracle Programs-1 - 240919 - 101202

Vb and oracle jpg

Uploaded by

kathirkanth74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views64 pages

Visual Basics and Oracle Programs-1 - 240919 - 101202

Vb and oracle jpg

Uploaded by

kathirkanth74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

INDEX

S.NO DATE CONTENTS PAGE REMARKS


NO
VISUAL BASICS
1. CALCULATOR 3

2. FIBONACCI SERIES AND SUM OF DIGITS 10

3. MENU DRIVEN PROGRAM USING MDI 15


WINDOW

4. DISPLAY FILES USING LISTBOXES 19

5. ACCESSING FILES USING COMMON DIALOG 25


BOX

6. ANIMATION USING TIMER 31

7. NUMBER CONVERSION 36

ORACLE
8. EMPLOYEE DETAILS 41

9. UPDATE AND ALTER THE TABLE USING 46


PL/SQL

10. IMPLEMENTING THE CONCEPT OF TRIGGERS 49

11. IMPLEMENTING THE CONCEPT OF 53


PROCEDURES

12. STUDENT MARKLIST 56

1
VISUAL BASIC

2
EX.NO : 01
CALCULATOR
DATE :

AIM:

To create a simple Visual Basic calculator program which include the basic mathematic function
like addition, subtraction, multiplication and division.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Place the appropriate controls on the form (1 Frame,1 text box, 16 command buttons and

set the properties using control array).

Step 4 : Set the property for all the controls in the form.

Step 5 : Write code for each event.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

3
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption Calculator
Frame 1 Caption Calculator
Text 1 Text None
Command1 Name Command1
Caption 1
Index 0
Command2 Name Command1
Caption 2
Index 1
Command3 Name Command1
Caption 3
Index 2
Command4 Name Command4
Caption +
Command5 Name Command1
Caption 4
Index 3
Command6 Name Command1
Caption 5
Index 4
Command7 Name Command1
Caption 6
Index 5
Command8 Name Command8
Caption -
Command9 Name Command1
Caption 7
Index 6
Command10 Name Command1
Caption 8
Index 7
Command11 Name Command1
Caption 9
Index 8
Command12 Name Command12

4
Caption *
Command13 Name Command1
Caption 0
Index 9
Command14 Name Command14
Caption AC
Command15 Name Command15
Caption =
Command16 Name Command16
Caption /

FORM DESIGN:

5
CODING:

Public curval As Double

Public preval As Double

Public choice As String

Public result As Double

Private Sub Command1_Click(Index As Integer)

Text1.Text = Text1.Text & Command1(Index).Caption

curval = Val(Text1.Text)

End Sub

Private Sub Command12_Click()

Text1.Text = ""

preval = curval

curval = 0

choice = "*"

End Sub

Private Sub Command14_Click()

preval = curval = 0

Text1.Text = ""

End Sub

Private Sub Command15_Click()

Select Case choice

Case "+"

6
result = preval + curval

Text1.Text = Str(result)

Case "-"

result = preval - curval

Text1.Text = Str(result)

Case "*"

result = preval * curval

Text1.Text = Str(result)

Case "/"

result = preval / curval

Text1.Text = Str(result)

End Select

curval = result

End Sub

Private Sub Command16_Click()

Text1.Text = ""

preval = curval

curval = 0

choice = "/"

End Sub

Private Sub Command4_Click()

Text1.Text = ""

preval = curval

curval = 0

choice = "+"

7
End Sub

Private Sub Command8_Click()

Text1.Text = ""

preval = curval

curval = 0

choice = "-"

End Sub

8
OUTPUT:

Result:

Thus the Visual Basic Program has been executed successfully.

9
EX.NO : 02
FIBONACCI SERIES AND SUM OF DIGITS
DATE :

AIM:

To write a simple Visual Basic program to generate Fibonacci Series and Sum of n-numbers.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Draw a textbox for accepting the number from the user and draw one listbox for displaying

the Fibonacci series and sum of numbers.

Step 4 : Draw a button for performing the Fibonacci operation and another button for performing

the sum operation, you can use more buttons for performing the multiple operation like

clear, exit, etc…

Step 5 : Double click on the button which you want to perform the Fibonacci operation, then type

the following coding of the Fibonacci series.

Step 6 : Double click on the button which you want to perform the sum operation, then type the

following coding of the sum of numbers.

Step 7 : Save the project and run the project.

Step 8 : Stop the process.

10
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption FB & SD
Label1 Name Label1
Caption Enter the Number
Command1 Name Command1
Caption Fibonacci Series
Command2 Name Command2
Caption Display Sum
Command3 Name Command3
Caption Clear
Command4 Name Command4
Caption Exit
Text1 Name Text1
Caption None
List1 Name List1
Caption None
FORM DESIGN:

11
CODING:

Private Sub Command1_Click()

Dim f, s, ans, n As Integer

n = Val(Text1.Text)

ans = 0

f=0

s=1

List1.AddItem f

List1.AddItem s

cnt = 2

While (cnt < n)

ans = f + s

List1.AddItem ans

f=s

s = ans

cnt = cnt + 1

Wend

End Sub

Private Sub Command2_Click()

Dim n, sum, cnt, rem1 As Integer

n = Val(Text1.Text)

sum = 0

While (n > 0)

sum = sum + (n Mod 10)

n = n \ 10

12
Wend

List1.AddItem sum

End Sub

Private Sub Command3_Click()

List1.Clear

Text1.Text = ""

End Sub

Private Sub Command4_Click()

End

End Sub

13
OUTPUT:

Result:

Thus the Visual Basic Program has been executed successfully.

14
EX.NO : 03
MENU DRIVEN PROGRAM USING MDI WINDOW
DATE :

AIM:

To write a Visual Basic program to develop a menu driven program using mdi window to display
cascade and horizontal style and change the color form.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Open a mdi form and make it as a child of form1, form2, form3.

Step 4 : In mdi form using menu editor window create menu’s and sub menu’s.

Step 5 : Menu as file and sun menu as new, cascade, horizontal an exit.

Step 6 : Other menu as color and sub menu as red, green and blue.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

15
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
MDI Child True
Form 2 Name Form2
MDI Child True
Form 3 Name Form3
MDI Child True
MDI Form 1 Name MDI Form1
Caption MDI Program
MDI Child True

MENU EDITOR SETTING:

MENU CAPTION VALUES


File File mnufile
…New New mnunew
…Cascade Cascade mnucascade
…Horizontal Horizontal mnuhorizontal
…Exit Exit mnuexit
Color Color mnucolor
…Red Red mnured
…Green Green mnugreen
…Blue Blue mnublue
FORM DESIGN:

16
CODING:

Private Sub mnublue_Click()

Form1.BackColor = vbBlue

End Sub

Private Sub mnuexit_Click()

End

End Sub

Private Sub mnugreen_Click()

Form2.BackColor = vbGreen

End Sub

Private Sub mnuhorizontal_Click()

MDIForm1.Arrange vbHorizontal

End Sub

Private Sub mnunew_Click()

Dim newform As New Form1

newform.Show

End Sub

Private Sub mnured_Click()

Form3.BackColor = vbRed

End Sub

17
Private Sub mnucascade_Click()

MDIForm1.Arrange vbVertical

End Sub

OUTPUT:

Result:

Thus the Visual Basic Program has been executed successfully.

18
EX.NO : 04
DISPLAY FILES USING LISTBOXES
DATE :

AIM:

To write a Visual Basic program to display files in a directory using DriveListBox,


DirectoryListBox and FileListBox Control and open, edit and save text file using RichTextBox Control.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Place four labels, two command buttons, one CommonDialog, one DriveListbox, one

DirectoryListBox, one FileListBox and one RichTextBox in the form and change their

corresponding properties.

Step 4 : Double click on the buttons and then type the corresponding coding of the buttons.

Step 5 : Save the project and run the project.

Step 6 : Stop the process.

19
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption ListBoxes
Label1 Name Label1
Caption Drive:
Label2 Name Label2
Caption Directories:
Label3 Name Label3
Caption Files in:
Label4 Name CurrentDir
Caption None
Label5 Name Label5
Caption Selected File:
Label6 Name SelectedFileName
Caption None
Command1 Name Command1
Caption Save
Command2 Name Command2
Caption Exit
RichTextBox1 Name txtFileContent
Caption None
CommonDialog1 Name CommonDialog1
DriveListbox Name Drive1
DirListBox Name Dir1
FileListBox Name File1
FORM DESIGN:

20
CODING:
Option Explicit

Private mstrDrive As String

Private Sub Command1_Click()

On Error Resume Next

CommonDialog1.ShowSave

CommonDialog1.Filter = ".txt"

txtFileContent.SaveFile (CommonDialog1.FileName)

txtFileContent.Text = ""

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Dir1_Change()

File1.Path = Dir1.Path

CurrentDir.Caption = Dir1.Path

If File1.ListCount > 0 Then

File1.ListIndex = 0

Else

SelectedFileName.Caption = "(None)"

txtFileContent.Text = ""

End If

End Sub

Private Sub Dir1_Click()

21
With Dir1.Path = .List(.ListIndex)

End With

End Sub

Private Sub Drive1_Change()

On Error Resume Next

Dir1.Path = Drive1.Drive

If Err.Number <> 0 Then

MsgBox "Drive selected is unavailable.", vbInformation, "Drive Unavailable"

Drive1.Drive = mstrDrive

Else

mstrDrive = Drive1.Drive

End If

End Sub

Private Sub File1_Click()

Dim strFileExt As String

Dim strCurrFile As String

Dim strFileContent As String

Dim intFreeFile As Integer

Dim lngFileLen As Long

Dim lngX As Long

Dim blnIsTextFile As Boolean

If File1.ListIndex = -1 Then Exit Sub

With File1

strCurrFile = IIf(Right$(.Path, 1) = "\", .Path, .Path & "\") _

& .List(.ListIndex)

22
End With

SelectedFileName.Caption = strCurrFile

lngFileLen = FileLen(strCurrFile)

If lngFileLen >= 65536 Then

txtFileContent.Text = "*** Selected file is too large to be displayed. ***"

Else

intFreeFile = FreeFile

Open strCurrFile For Binary Access Read As #intFreeFile

strFileContent = Input(LOF(intFreeFile), intFreeFile)

Close #intFreeFile

blnIsTextFile = True

For lngX = 1 To lngFileLen

Select Case Asc(Mid$(strFileContent, lngX, 1))

Case 0 To 8, 11 To 12, 14 To 31

blnIsTextFile = False

Exit For

End Select

Next

If blnIsTextFile Then

txtFileContent.Text = strFileContent

Else

txtFileContent.Text = "*** Selected file is not a plain text file. ***"

End If

End If

End Sub

23
Private Sub Form_Load()

Drive1.Drive = "C:"

mstrDrive = "C:"

Dir1.Path = "C:\"

End Sub

OUTPUT:

Result:

Thus the Visual Basic Program has been executed successfully.

24
EX.NO : 05 ACCESSING FILES USING COMMON DIALOG
DATE : BOX

AIM:

To design a form using common Dialog Control to display the open, save, color and font dialog
box without using the action control property.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Design the form by placing Common Dialog Control and RichTextBox.

Step 4 : Open the Project  Components  Microsoft Common Dialog 6.0 apply menu editor

window and then create required menu is file and sub menu’s as open, font, color and exit.

Step 5 : In the code editor window write code for accessing files using Common Dialog Control

and display the result in RichTextBox.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

25
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption Common Dialog Control
RichTextBox1 Name RichTextBox1
Text None
CommonDialog1 Name CommonDialog1

MENU EDITOR SETTING:

MENU CAPTION VALUES


File File mnufile
…Open Open mnuopen
…Save Save mnusave
…Color Color mnucolor
…Font Font mnufont
…Exit Exit mnuexit

FORM DESIGN:

26
CODING:
Private Sub mnucolor_Click()

On Error Resume Next

CommonDialog1.ShowColor

RichTextBox1.BackColor = CommonDialog1.Color

End Sub

Private Sub mnuexit_Click()

End

End Sub

Private Sub mnufont_Click()

On Error GoTo cancel

CommonDialog1.Flags = cd1cfboth Or cdcfefferts

CommonDialog1.ShowFont

RichTextBox1.Font.Name = CommonDialog1.FontName

RichTextBox1.Font.Bold = CommonDialog1.FontBold

RichTextBox1.Font.Italic = CommonDialog1.FontItalic

RichTextBox1.Font.Underline = CommonDialog1.FontUnderline

RichTextBox1.Font.Size = CommonDialog1.FontSize

cancel:

End Sub

Private Sub mnuopen_Click()

On Error Resume Next

CommonDialog1.Filter = ".txt"

CommonDialog1.ShowOpen

27
RichTextBox1.FileName = CommonDialog1.FileName

End Sub

Private Sub mnusave_Click()

On Error Resume Next

CommonDialog1.ShowSave

CommonDialog1.Filter = ".txt"

RichTextBox1.SaveFile (CommonDialog1.FileName)

RichTextBox1.Text = ""

End Sub

28
OUTPUT:

29
Result:

Thus the Visual Basic Program has been executed successfully.

30
EX.NO : 06
ANIMATION USING TIMER
DATE :

AIM:

To write a simple Visual Basic program to implement animation using timer.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Place one command button, eight image box and one timer in the form.

Step 4 : Insert a group of eight images of a flapping butterfly its wings at different stages in the

image box.

Step 5 : Set the timer properties and then type the corresponding coding of the buttons.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

31
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption Animation Using Timer
Command1 Name Command1
Caption Animate
Timer1 Name Timer1
Enabled False
Interval 50
Image1 Picture Image1
Image2 Picture Image2
Image3 Picture Image3
Image4 Picture Image4
Image5 Picture Image5
Image6 Picture Image6
Image7 Picture Image7
Image8 Picture Image8

FORM DESIGN:

32
CODING:
Private Sub Command1_Click()

Timer1.Enabled = True

End Sub

Private Sub Form_Load()

Image1.Visible = True

X=0

End Sub

Private Sub Timer1_Timer()

If Image1.Visible = True Then

Image1.Visible = False

Image2.Visible = True

ElseIf Image2.Visible = True Then

Image2.Visible = False

Image3.Visible = True

ElseIf Image3.Visible = True Then

Image3.Visible = False

Image4.Visible = True

ElseIf Image4.Visible = True Then

Image4.Visible = False

Image5.Visible = True

ElseIf Image5.Visible = True Then

Image5.Visible = False

Image6.Visible = True

ElseIf Image6.Visible = True Then

33
Image6.Visible = False

Image7.Visible = True

ElseIf Image7.Visible = True Then

Image7.Visible = False

Image8.Visible = True

ElseIf Image8.Visible = True Then

Image8.Visible = False

Image1.Visible = True

End If

End Sub

34
OUTPUT:

Result:

Thus the Visual Basic Program has been executed successfully.

35
EX.NO : 07
NUMBER CONVERSION
DATE :

AIM:

To write a Visual Basic Program to accept a number as input and convert them into Binary, Octal
and hexadecimal.

ALGORITHM:

Step 1 : Start the process.

Step 2 : Create a new form using Visual Basic Standard(.exe).

Step 3 : Place four label boxes, four text boxes and two command buttons in the form.

Step 4 : Change their corresponding properties.

Step 5 : Type the corresponding coding for all the buttons.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

36
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption Number Conversion
Label1 Name Label1
Caption Enter the Number
Label2 Name Label2
Caption Binary
Label3 Name Label3
Caption Octal
Label4 Name Label4
Caption Hexadecimal
Text1 Text None
Text2 Text None
Text3 Text None
Text4 Text None
Command1 Name Command1
Caption Convert
Command2 Name Command2
Caption Exit
FORM DESIGN:

37
CODING:
Private Sub Command1_Click()

Dim a(20) As Variant, num As Integer

Text2.Text = ""

num = Val(Text1.Text)

i=0

While (num > 0)

a(i) = num Mod 2

Text2.Text = Str((a(i))) + Text2.Text

i=i+1

num = (num / 2)

Wend

Text3.Text = Oct(Text1.Text)

Text4.Text = Hex(Text1.Text)

End Sub

Private Sub Command2_Click()

End

End Sub

38
OUTPUT:

Result:

Thus the Visual Basic Program has been executed successfully.

39
ORACLE

40
EX.NO : 08
EMPLOYEE DETAILS
DATE :

AIM:

To create a table for employee details with employee number as primary key and following fields
Name, Designation, Gender, Age, Date of Joining and Salary. Insert at least ten rows and perform various
queries using any one comparison, logical, set, sorting and grouping operation.

ALGORITHM:

Step 1 : Start the process.

Step 2 : MYSQL  Run MYSQL command line.

Step 3 : Create and select a database and create a table.

Step 4 : This table contains as Empno, Name, Designation, Gender, Age, DOJ, Salary with their

primary key by using the table.

Step 5 : Insert values into the table.

Step 6 : Then perform operation like comparison, logical, set, sorting and grouping – average, sum,

maximum, minimum and count.

Step 7 : Display the describe of the table.

Step 8 : Stop the process.

41
QUERIES:
MYSQL > create database empl;

Query OK

MYSQL > use empl;

Database changed

MYSQL > create table empl(Empno int(2),primary key(Empno),Name varchar(20)not null,Designation


varchar(20),Gender char(1)not null,Age int(3)not null,Doj date,Salary int(5));

Query OK

MYSQL > desc empl;

Field Type Null Key Default


---------------- --------------- ------ ----- ---------
Empno int NO PRI Null
Name varchar(20) NO Null
Designation varchar(20) YES Null
Gender char(1) NO Null
Age int NO Null
Doj date YES Null
Salary int YES Null

7 rows in set

MYSQL > insert into empl values (5,'PM','MD','M',35,'1980-02-01',5000);

Query OK.

MYSQL > insert into empl values (2,'SURYA','GM','M',38,'1990-05-07',10000);

Query OK.

MYSQL > insert into empl values (6,'SOFI','ASSISTANT','F',40,'1992-06-19',3000);

Query OK.

MYSQL > insert into empl values (10,'SWETHA','SECRETARY','F',39,'1983-07-11',4000);

Query OK.

MYSQL > insert into empl values (13,'SWATHI','INCHARGE','F',25,'1996-05-21',6000);

42
Query OK.

MYSQL > insert into empl values (20,'RAM','CLEANER','M',45,'1982-09-05',3000);

Query OK.

MYSQL > select * from empl;

Empno Name Designation Gender Age DOJ Salary


---------- --------------- ------------------ ----- ------ ---------------- --------
2 SURYA GM M 38 1990-05-07 10000
5 PM MD M 35 1980-02-01 5000
6 SOFI ASSISTANT F 40 1992-06-19 3000
10 SWETHA SECRETARY F 39 1983-07-11 4000
13 SWATHI INCHARGE F 25 1996-05-21 6000
20 RAM CLEANER M 45 1982-09-05 3000
6 rows in set

MYSQL >select * from empl order by Empno desc;

Empno Name Designation Gender Age DOJ Salary


---------- --------------- ------------------ ----- ------ ---------------- --------
20 RAM CLEANER M 45 1982-09-05 3000
13 SWATHI INCHARGE F 25 1996-05-21 6000
10 SWETHA SECRETARY F 39 1983-07-11 4000
6 SOFI ASSISTANT F 40 1992-06-19 3000
5 PM MD M 35 1980-02-01 5000
2 SURYA GM M 38 1990-05-07 10000

6 rows in set

MYSQL >select sum(Salary),avg(Salary),max(Salary),min(Salary) from empl;

sum(Salary) avg(Salary) max(Salary) min(Salary)


---------------- -------------- -------------- -------------
31000 5166.6667 10000 3000
1 rows in set

MYSQL >select Empno,Name,Designation,Gender,Age from empl where Salary>=4000 and


Salary<=6000;

Empno Name Designation Gender Age

43
---------- --------------- ------------------ ----- ------
5 PM MD M 35
10 SWETHA SECRETARY F 39
13 SWATHI INCHARGE F 25

3 rows in set

MYSQL >select Name from empl where Name between 'S' and 'U';

Name
---------------
SURYA
SOFI
SWETHA
SWATHI

4 rows in set

MYSQL >create table empy(Empno int(2),primary key(Empno),Name varchar(20)not null,Designation


varchar(20),Gender char(1)not null,Age int(3)not null,Doj date,Salary int(5));

Query OK.

MYSQL > insert into empy values (1,'KRISHNA','MECHANIC','M',30,'1991-02-01',7000);

Query OK.

MYSQL > insert into empy values (7,'PRIYA','PROGRAMMER','F',36,'1989-06-25',9000);

Query OK.

MYSQL > select Empno,Name from empl

Union

select Empno,Name from empy;

Empno Name
---------- ---------------
2 SURYA
5 PM
6 SOFI
10 SWETHA
13 SWATHI

44
20 RAM
1 KRISHNA
7 PRIYA

8 rows in set

Result:

Thus the MYSQL program has been executed successfully.

45
EX.NO : 09
UPDATE AND ALTER THE TABLE USING PL/SQL
DATE :

AIM:

To write a PL/SQL to update the fieldscreate fields by 20% more than the current rate in inventory
table which has the following fields Prono, Proname and Rate after updating the table anew fields(after)
called for number of item and place for value for the new field without using PL/SQL blocks.

ALGORITHM:

Step 1 : Start the process.

Step 2 : MYSQL  Run MYSQL command line.

Step 3 : Create a table as Prono, Proname and Rate by using the table.

Step 4 : PL/SQL to update the rate field by 20% more than the current rate in inventory table.

Step 5 : Alter the table into adding the no of item and place for values.

Step 6 : Display the describe of the table.

Step 7 : Stop the process.

46
QUERIES:
MYSQL > create database employees;

Query OK.

MYSQL > use employees;

Database Changed.

MYSQL > create table inventry(ProdNo int(5),primary key(ProdNo),ProdName varchar(20) not null,Rate
int(10));

Query OK.

MYSQL > insert into inventry values(1,'Clothes',50);

Query OK.

MYSQL > insert into inventry values(2,'Dal',90);

Query OK.

MYSQL > insert into inventry values(3,'Oil',100);

Query OK.

MYSQL > select * from inventry;

ProdNo ProdName Rate


--------------- ------------------ -----------
1 Clothes 50
2 Dal 90
3 Oil 100

3 rows in set

MYSQL > set sql_safe_updates=0;


Query OK.

MYSQL > update inventry set Rate = Rate *1.20;

Query OK.

MYSQL > select * from inventry;

47
ProdNo ProdName Rate
--------------- ------------------ -----------
1 Clothes 60
2 Dal 108
3 Oil 120

3 rows in set

MYSQL >alter table inventry add noofitem int(5);


Query OK.

MYSQL >alter table inventry add placeforvalues int(2);

Query OK.

MYSQL >set sql_safe_updates=1;

Query OK.

MYSQL > select * from inventry;

ProdNo ProdName Rate noofitem placeforvalues


--------------- ------------------ ----------- -------------- ------------------
1 Clothes 60 NULL NULL
2 Dal 108 NULL NULL
3 Oil 120 NULL NULL

3 rows in set

Result:

Thus the MYSQL program has been executed successfully.

48
EX.NO : 10
IMPLEMENTING THE CONCEPT OF TRIGGERS
DATE :

AIM:

To write a PL/SQL program to implement the concept of triggers.

ALGORITHM:

Step 1 : Start the process.

Step 2 : MYSQL  Run MYSQL command line.

Step 3 : Create a table as test1, test2, test3 and test4 tables.

Step 4 : This table contains column as a1, a2, a3, a4 and b4.

Step 5 : Create database trigger as textref.

Step 6 : Display the describe of the table.

Step 7 : Stop the process.

49
QUERIES:
MYSQL > create database list;

Query OK.

MYSQL > use list;

Database Changed.

MYSQL > create table test1(a1 int);

Query OK.

MYSQL > create table test2(a2 int);

Query OK.

MYSQL > create table test3(a3 int not null auto_increment primary key);

Query OK.

MYSQL > create table test4(a4 int not null auto_increment primary key,

b4 int default 0);

Query OK.

MYSQL > delimiter |

MYSQL > create trigger testref before insert on test1

for each row

begin

insert into test2 set a2 = new.a1;

delete from test3 where a3 = new.a1;

update test4 set b4 = b4 + 1 where a4 = new.a1;

end;

MYSQL > delimiter ;

MYSQL > insert into test3 (a3) values (null), (null), (null), (null), (null),

(null), (null), (null), (null), (null);

50
Query OK.

MYSQL > insert into test4 (a4) values (0), (0), (0), (0), (0), (0), (0), (0), (0), (0);

Query OK.

MYSQL > insert into test1 values (1), (3), (1), (7), (1), (8), (4), (4);

Query OK.

MYSQL > select * from test1;

a1
------
1
3
1
7
1
8
4
4

8 rows in set

MYSQL > select * from test2;

a2
------
1
3
1
7
1
8
4
4

8 rows in set

MYSQL > select * from test3;

51
a3
------
2
5
6
9
10

5 rows in set

MYSQL > select * from test4;

a4 b4
------ ------
1 3
2 0
3 1
4 2
5 0
6 0
7 1
8 1
9 0
10 0

10 rows in set

Result:

Thus the MYSQL program has been executed successfully.

52
EX.NO : 11 IMPLEMENTING THE CONCEPT OF
DATE : PROCEDURES

AIM:

To write a PL/SQL program to implement the concept of procedures.

ALGORITHM:

Step 1 : Start the process.

Step 2 : MYSQL  Run MYSQL command line.

Step 3 : Create a table employees with the fields employee_id, employee_name and salary.

Step 4 : Create procedure like InsertEmployee, UpdateEmployee and GetEmployeeByName.

Step 5 : Call procedure InsertEmployee to insert value into table.

Step 6 : Call procedure UpdateEmployee to change existing values in the table.

Step 7 : Call procedure GetEmployeeByName to get the details of an employee.

Step 8 : Display the describe of the table.

Step 9 : Stop the process.

53
QUERIES:
MYSQL > create database details;

Query OK.

MYSQL > use details;

Database Changed.

MYSQL > create table employees (employee_id int auto_increment primary key, employee_name
varchar(255) not null, salary decimal(10, 2) not null);

Query OK.

MYSQL > delimiter //

MYSQL > create procedure insertemployee(in emp_name varchar(255), in emp_salary decimal(10, 2))

begin

insert into employees (employee_name, salary) values (emp_name, emp_salary);

end;

//

MYSQL > delimiter ;

MYSQL > call insertemployee('alice smith', 60000.00);

Query OK.

MYSQL > select * from employees;

employee_id employee_name salary


------------------ ---------------------- -----------
1 Alice Smith 60000.00

1 row in set

MYSQL >delimiter //

MYSQL >create procedure updatesalary(in emp_id int, in new_salary decimal(10, 2))


begin
update employees set salary = new_salary where employee_id = emp_id;
end;

54
//
MYSQL >delimiter ;
MYSQL >call updatesalary(1, 65000.00);
Query OK.

MYSQL > delimiter //


MYSQL > create procedure getemployeebyname(in emp_name varchar(255))
begin
select * from employees where employee_name = emp_name;
end;
//
MYSQL > delimiter ;
MYSQL > call getemployeebyname('alice smith');

employee_id employee_name salary


------------------ ---------------------- -----------
1 Alice Smith 65000.00

1 row in set

Result:

Thus the MYSQL program has been executed successfully.

55
EX.NO : 12
STUDENT MARKLIST
DATE :

AIM:

To create a simple Visual Basic project for student marklist using VB as front-end and MYSQL as
back-end.

ALGORITHM:

Step 1 : Start the process.

Step 2 : MYSQL  Run MYSQL command line for Back-end usage.

Step 3 : The student table is created using create table student query with Student_Name,

Student_Dept and Marks fields.

Step 4 : The values are inserted in student table using INSERT command.

Step 5 : In order to view the student record select * from student query is used.

Step 6 : To use the Visual basic as front end, click on Start → All Programs → Microsoft Visual

Basic 6.0 – New Project.

Step 7 : Draw three labels, three textboxes, five command button and one ADODC Control.

Step 8 : Change the caption for the controls using properties window.

56
Step 9 : To connect ADODC Control to MYSQL database, Right click on the ADODC and select

ADODC properties, Select on Use Connection String and Click Build, Select the Microsoft

OLE DB Provider for ODBC Drivers. Then Enter the Data Source Name, Username and

Password and Click Test Connection and then OK.

Step 10 : Create a new form and Place One ADODC Control and One DataGrid Control, Connect

the ADODC Control to MYSQL database.

Step 11 : Connect DataGrid Control to ADODC Control and Right click on ADODC and Set

RecordSource, username and password.

Step 12 : Open the code editor window and write appropriate coding.

Step 13 : Save the project and run the project.

Step 14 : Stop the process.

57
PROPERTY SETTING:

OBJECT PROPERTY VALUES


Form 1 Name Form1
Caption Student Marklist
Label1 Name Label1
Caption STUDENT NAME
Label2 Name Label2
Caption DEPARTMENT
Label3 Name Label3
Caption MARKS
Text1 Name txtStudentName
Text None
Text2 Name txtDept
Text None
Text3 Name txtMarks
Text None
Command1 Name btnAdd
Caption ADD
Command2 Name btnUpdate
Caption UPDATE
Command3 Name btnDelete
Caption DELETE
Command4 Name btnView
Caption VIEW
Command5 Name btnExit
Caption EXIT
Adodc1 Name Adodc1
CommandType 2-adCmdTable
RecordSource Student
Visible False
Form 2 Name Form2
Caption DataView
Adodc1 Name Adodc1
CommandType 2-adCmdTable
RecordSource student
Visible False
DataGrid1 Name DataGrid1
Caption STUDENT MARKLIST
DataSource Adodc1

58
FORM DESIGN:

59
MYSQL QUERIES:
MYSQL >create database student_marklist;

Query OK.

MYSQL >use student_marklist;

Database Changed.

MYSQL >create table student (Student_Name varchar(50), Student_Dept varchar(10), Marks int(3));

Query OK.

MYSQL >insert into student values (‘Babu’,’III Bsc CS’,536);

Query OK.

MYSQL >select * from student;

Student_Name Student_Dept Marks


--------------------- ------------------- -----------
Babu III Bsc CS 536

1 row in set

Visual Basic Coding:


Private conn As New ADODB.Connection
Private rs As New ADODB.Recordset

Private Sub btnExit_Click()


End
End Sub

Private Sub btnView_Click()


Form2.Show
End Sub

60
Private Sub Form_Load()
conn.ConnectionString = "DSN=sql;"
conn.Open
End Sub

Private Sub btnAdd_Click()


Dim studentName As String
Dim studentDept As String
Dim marks As Integer

studentName = txtStudentName.Text
studentDept = txtDept.Text
marks = Val(txtMarks.Text)
conn.Execute "INSERT INTO student (Student_Name,Student_Dept,Marks) VALUES ('" & studentName
& "','" & studentDept & "', '" & marks & "')"
MsgBox "Student added successfully!", vbInformation, "Success"
txtStudentName.Text = ""
txtDept.Text = ""
txtMarks.Text = ""
End Sub

Private Sub btnUpdate_Click()


Dim studentName As String
Dim newMarks As Integer
Dim studentDept As String

studentName = txtStudentName.Text
studentDept = txtDept.Text
newMarks = Val(txtMarks.Text)

61
conn.Execute "UPDATE student SET Marks = " & newMarks & " WHERE Student_Name = '" &
studentName & "'and Student_Dept = '" & studentDept & "'"
MsgBox "Marks updated successfully!", vbInformation, "Success"
txtStudentName.Text = ""
txtDept.Text = ""
txtMarks.Text = ""
End Sub

Private Sub btnDelete_Click()


Dim studentName As String
Dim studentDept As String

studentName = txtStudentName.Text
studentDept = txtDept.Text
conn.Execute "DELETE FROM student WHERE Student_Name = '" & studentName & "' and
Student_Dept = '" & studentDept & "' "
MsgBox "Student deleted successfully!", vbInformation, "Success"
txtStudentName.Text = ""
txtDept.Text = ""
End Sub

Private Sub Form_Unload(Cancel As Integer)


conn.Close
Set conn = Nothing
End Sub

62
OUTPUT:

63
Result:

Thus the Visual Basic and MYSQL program has been executed successfully.

64

You might also like