0% found this document useful (0 votes)
24 views48 pages

RAKSHITHA-VB2[2]

Uploaded by

Meghashree.s
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)
24 views48 pages

RAKSHITHA-VB2[2]

Uploaded by

Meghashree.s
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/ 48

****************************************************************

NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM 1: Design a VB form to accept a number and display its
factorial. Input is to be accepted using textbox and the output can be
displayed using textbox or label. Perform validation for empty input, non-
numeric input, as well as negative input and display error message
accordingly using a message box.

DESIGN VIEW:

PROGRAM CODE:

Public Class Form1


Private Sub Form1_Load()
Label1.Visible = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim a, i As Integer
Dim fact As Long = 1
If TextBox1.Text = "" Then
MessageBox.Show("Textbox is Empty")
ElseIf IsNumeric(TextBox1.Text) = False Then
MessageBox.Show("please Enter only a number")
Else

1
a = Val(TextBox1.Text)
If a < 0 Then
MessageBox.Show("Enter only positive number")
Else
For i = 1 To a
fact = fact * i
Next
Label1.Visible = True
Label1.Text = "Factorial of" & a & "is:" & fact.ToString()
End If
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
TextBox1.Text = " "
Label1.Text = " "
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
End
End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles


Label1.Click
End Sub
End Class

OUTPUT:

2
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 2: Design a VB interface containing

a) A picture box whose oicture should be changed every 5 second(use 5


pictures).
b) Textboxes to display date and time and day greetiing based on time.
Time has to be changed every second automatically.
c) Use scrollbars to change font size and background color(RGB) of the
textbox that shows greeting.(use timer,scrollbars).

DESIGN VIEW:

PROGRAM CODE:

Public Class Form1


Dim i As Integer = 0
Dim a() As String = {"a", "b", "c", "d", "e"}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
Timer1.Enabled = True

3
If (DateTime.Now.TimeOfDay.Hours >= 12 And
DateTime.Now.TimeOfDay.Hours <= 15) Then
Txtgreeting.Text = "GOOD AFTERNOON"
ElseIf (DateTime.Now.TimeOfDay.Hours > 15 And
DateTime.Now.TimeOfDay.Hours <= 20) Then
Txtgreeting.Text = "GOOD EVENING"
ElseIf (DateTime.Now.TimeOfDay.Hours > 20 And
DateTime.Now.TimeOfDay.Hours <= 24) Then
Txtgreeting.Text = "GOOD NIGHT"
Else
Txtgreeting.Text = "GOOD MORNING"
End If
End Sub

Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs)


Handles HScrollBar1.Scroll
Txtgreeting.BackColor = Color.FromArgb(255 * Rnd(), 255 * Rnd(), 255 *
Rnd())
End Sub

Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs)


Handles VScrollBar1.Scroll
Dim fnt As Font
fnt = Txtgreeting.Font
Txtgreeting.Font = New Font(fnt.Name, VScrollBar1.Value + 1,
FontStyle.Bold)
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles


Timer1.Tick
txtdate.Text = Date.Now.ToString("dd-MM-yyyy")
txttime.Text = Date.Now.ToString("hh:mm:ss")
Me.PictureBox1.Image = Image.FromFile("C:\Users\BCA-LAB.BCA-
LAB030\Pictures\" + a(i) + ".jpg")
i=i+1
If (i = 4) Then
i=0
End If
End Sub

4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
End
End Sub
End Class

OUTPUT:

5
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 3: Design a VB interface to add, remove, search and clear the


items in a combo box .The item name to be added, removed or searched
can be accepted through input box. Use a general procedure to find the
existence of item before deleting or while searching.

DESIGN VIEW:

PROGRAM CODE:

Public Class Form1


Dim a As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
ComboBox1.Items.Add(InputBox("Enter a String"))
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
a = (InputBox("Enter a String"))
If check(a) Then
ComboBox1.Items.Remove(a)
Else

6
MsgBox("No Items")
End If
End Sub
Public Function check(ByVal a As String) As Boolean
If ComboBox1.Items.Contains(a) Then
Return True
Else
Return False
End If

End Function

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
a = InputBox("Enter a String")
If check(a) Then
MsgBox("Item found")
Else
MsgBox("No Item")
End If
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click
ComboBox1.Items.Clear()
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


Button5.Click
End
End Sub
End Class

7
OUTPUT:

8
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 4: Write a VB program find GCD and LCM of two number.


Accept input through textbox and display the results in label. Also validate
for invalid input such as empty input, non-numeric and negative integer.

DESIGN VIEW:

PROGRAM CODE:

Public Class Form1

Private Sub BtnGCDLCM_Click(sender As Object, e As EventArgs) Handles


BtnGCDLCM.Click
If TxtNum1.Text = Nothing Or TxtNum2.Text = Nothing Then
MsgBox("Empty input.please enter some data")
Exit Sub
End If
If IsNumeric(TxtNum1.Text) = False Then
MsgBox("Non numeric input.please enter number")
TxtNum1.Clear()
TxtNum1.Focus()
Exit Sub
End If
If IsNumeric(TxtNum2.Text) = False Then

9
MsgBox("Non numeric input.please enter number")
TxtNum1.Clear()
TxtNum1.Focus()
Exit Sub

End If
If Val(TxtNum1.Text) < 0 Then
MsgBox("Enter a positive number")
TxtNum1.Clear()
TxtNum1.Focus()
Exit Sub

End If
If Val(TxtNum2.Text) < 0 Then
MsgBox("Enter a positive integer")
TxtNum2.Clear()
TxtNum2.Focus()
Exit Sub
End If
Dim a, b, prod, lcm As Integer
a = Val(TxtNum1.Text)
b = Val(TxtNum2.Text)
prod = a * b
While a <> b
If a > b Then a = a - b
If b > a Then b = b - a

End While
lcm = prod / a
Label5.Text = a
Label6.Text = lcm

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
TxtNum1.Text = " "
TxtNum2.Text = " "

10
Label5.Text = " "
Label6.Text = " "
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
End
End Sub
End Class

OUTPUT:

11
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 5: write a program in c# to check a number if it is


prime;otherwise display the factor of that number.

PROGRAM CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prime_number
{
class Program
{
static void Main(string[] args)
{
int num, i, f = 0;
Console.Write("Enter a number.");
num = int.Parse(Console.ReadLine());
for (i = 1; i <= num; i++)
{
if (num % i == 0)
{
f++;
}
}
if (f == 2)
{
Console.WriteLine("Number is prime.");
}
else
{
Console.WriteLine("Number is not prime.");
int factor;

12
for(factor=1;factor<=num;factor++)
{
if(num%factor==0)
{
Console.Write(factor+",");
}
}
}
Console.ReadLine();
}
}
}

OUTPUT:

13
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 6:Write a program in c# define a class “salary” which will


contain member variable emp_no, emp_name,dob, basic. Write a program
using constructor. And method to calculate the da, hra,pf,it,gross and
netpay using appropriate condition.
If basic<=20000 DA is 40% basic HRA is 10% basic
PF 12% of gross; PT is Rs.100
If basic>20000 DA is 50% basic HRA is 15% basic
PF 12% of gross; PT is Rs.150
Gross=Basic+DA+HRA and Net=Gross-PT-PF

PROGRAM CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace salary
{
class Program
{
public class salary
{
int emp_no;
string emp_name;
string dob;
double basic;
double da, hra, pf, pt, gross, netpay;
public salary(int no, string name, string db, double salary)
{
emp_no = no;
emp_name = name;
basic = salary;
dob = db;
da = 0;

14
hra = 0;
pf = 0;
pt = 0;
gross = 0;
netpay = 0;
}
void calculate(double basic)
{
if (basic <= 20000)
{
da = basic * 40 / 100;
hra = basic * 10 / 100;
gross = basic + da + hra;
pf = gross * 12 / 100;
pt = 100;
netpay = gross - pt - pf;
}
else if (basic > 20000)
{
da = basic * 50 / 100;
hra = basic * 15 / 100;
gross = basic + da + hra;
pf = gross * 12 / 100;
pt = 150;
netpay = gross - pt - pf;
}
}
void display()
{
Console.WriteLine("Employee Number:" + emp_no);
Console.WriteLine("Employee Name:" + emp_name);
Console.WriteLine("Date of birth:" + dob);
Console.WriteLine("salary:" + basic);
Console.WriteLine("dearness allowances:" + da);
Console.WriteLine("house rent allowance:" + hra);
Console.WriteLine("provident fund:" + pf);
Console.WriteLine("gross salary:" + gross);
Console.WriteLine("professional tax:" + pt);
Console.WriteLine("net salary:" + netpay);
}

15
static void Main(string[] args)
{
int empno;
string empname, dob;
double salary;
Console.WriteLine("enter your employee no:");
empno = int.Parse(Console.ReadLine());
Console.WriteLine("enter your name");
empname = Console.ReadLine();
Console.WriteLine("enter your date of birth dd-mm-yy:");
dob = Console.ReadLine();
Console.WriteLine("enter your salary:");
salary = double.Parse(Console.ReadLine());
salary sal = new salary(empno, empname, dob, salary);
sal.calculate(salary);
sal.display();
System.Console.ReadLine();
}
}
}
}

OUTPUT:

16
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 7: Write a program in c# to find addition and multiplication


operation on two complex number using operator overloading.

PROGRAM CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace complex
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the first real and imaginary number");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the second real and imaginary number");
int c = int.Parse(Console.ReadLine());
int d = int.Parse(Console.ReadLine());
complex c1 = new complex(a, b);
complex c2 = new complex(c, d);
complex c3 = new complex();
c3 = c1 + c2;
c3.Display();
complex c4 = new complex();
c4 = c1 * c2;
c4.Display();
Console.ReadKey();
}
}
public class complex

17
{
int real;
int img;
public complex(int r=0,int i=0)
{
real=r;
img=i;
}
public static complex operator+(complex c1,complex c2)
{
complex c3=new complex();
c3.real=c1.real+c2.real;
c3.img=c1.img+c2.img;
return c3;
}
public static complex operator*(complex c1,complex c2)
{
complex c3=new complex();
c3.real=c1.real*c2.real-c1.img*c2.img;
c3.img=c1.real*c2.img+c1.img*c2.real;
return c3;
}
public void Display()
{
Console.WriteLine(real+"+i"+img);
}
}
}

OUTPUT:

18
****************************************************************
NAME : RAKSHITHA

REG NO : U05SP22S0032
****************************************************************

PROGRAM 1: Design a simple calculator using VB interface perform


addition, multiplication, substraction and division.It should contain buttons
for the digits 0-9,clear,dot,=,+,-,*,/. Apply the validation rules to avoid
entering dot more than once in a number and using – symbol between the
digits. Symbol „-„ can be used as operator as well as for negative numbers.
Any operand can be negative. “Division by zero” to be displayed if divisor
is 0.

DESIGN VIEW:

PROGRAM CODE:

Public Class Form1


Dim flag As Boolean = True
Dim op As String
Dim opr As Double
Dim oper2 As Double
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click

19
If flag = True Then
TextBox1.Text = Button1.Text
flag = False
Else
TextBox1.Text &= Button1.Text
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
If flag = True Then
TextBox1.Text = Button2.Text
flag = False
Else
TextBox1.Text &= Button2.Text
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
If flag = True Then
TextBox1.Text = Button3.Text
flag = False
Else
TextBox1.Text &= Button3.Text
End If
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click
op = "+"
opr = Val(TextBox1.Text)
flag = True
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


Button5.Click
If flag = True Then
TextBox1.Text = Button5.Text
flag = False

20
Else
TextBox1.Text &= Button5.Text
End If
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles


Button6.Click
If flag = True Then
TextBox1.Text = Button6.Text
flag = False
Else
TextBox1.Text &= Button6.Text
End If
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles


Button7.Click
If flag = True Then
TextBox1.Text = Button7.Text
flag = False
Else
TextBox1.Text &= Button7.Text
End If
End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles


Button8.Click
If TextBox1.Text = " " Then
TextBox1.Text = "-"
flag = False
Else
op = "-"
opr = Val(TextBox1.Text)
flag = True
End If
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles


Button9.Click
If flag = True Then

21
TextBox1.Text = Button9.Text
flag = False
Else
TextBox1.Text &= Button9.Text
End If
End Sub

Private Sub Button10_Click(sender As Object, e As EventArgs) Handles


Button10.Click
If flag = True Then
TextBox1.Text = Button10.Text
flag = False
Else
TextBox1.Text &= Button10.Text
End If
End Sub

Private Sub Button11_Click(sender As Object, e As EventArgs) Handles


Button11.Click
If flag = True Then
TextBox1.Text = Button11.Text
flag = False
Else
TextBox1.Text &= Button11.Text
End If
End Sub

Private Sub Button12_Click(sender As Object, e As EventArgs) Handles


Button12.Click
op = "*"
opr = Val(TextBox1.Text)
flag = True
End Sub

Private Sub Button13_Click(sender As Object, e As EventArgs) Handles


Button13.Click
If flag = True Then
TextBox1.Text = Button13.Text
flag = False
Else

22
TextBox1.Text &= Button13.Text
End If
End Sub

Private Sub Button14_Click(sender As Object, e As EventArgs) Handles


Button14.Click
If Button14.Text = "." And flag Then
TextBox1.Text = "0."
flag = False
ElseIf TextBox1.Text.IndexOf(".") > 0 Then
Exit Sub
Else
TextBox1.Text = TextBox1.Text & "."
End If
End Sub

Private Sub Button16_Click(sender As Object, e As EventArgs) Handles


Button16.Click
op = "/"
opr = Val(TextBox1.Text)
flag = True
End Sub

Private Sub Button15_Click(sender As Object, e As EventArgs) Handles


Button15.Click
Dim oper2 As Double
Dim result As Double
oper2 = Val(TextBox1.Text)
Select Case op
Case "+"
result = opr + oper2
Case "-"
result = opr - oper2
Case "*"
result = opr * oper2
Case "/"
result = opr / oper2
If oper2 = 0 Then
MsgBox("division by zero")
End If

23
End Select
TextBox1.Text = result
flag = True
End Sub

Private Sub Button17_Click(sender As Object, e As EventArgs) Handles


Button17.Click
End
End Sub

Private Sub Button18_Click(sender As Object, e As EventArgs) Handles


Button18.Click
TextBox1.Text = ""
End Sub
End Class

OUTPUT:

24
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 2: Design VB interface to conduct simple multiple choice quiz


with at least five questions. For selecting the answers, use combo box and
Radio Button for few questions. One question can be answered only once.
Show the total score through the message box whenever the user wishes to
see his score in between the competition. Any question can be attempted
randomly.

DESIGN VIEW:

PROGRAM CODE:

Public Class Form1


Dim cans(5) As Integer
Dim i As Integer
Dim score As Integer
Dim clicked As Button
Private Sub changestatus()
GroupBox1.Visible = True
If i < 4 Then
GroupBox2.Visible = True
GroupBox3.Visible = False

25
Else
GroupBox2.Visible = False
GroupBox3.Visible = True
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
GroupBox1.Visible = False
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
i=0
changestatus()
clicked = sender
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
Label1.Text = "1.who is father of computer?"
RadioButton1.Text = "Martin luther"
RadioButton2.Text = "nisha"
RadioButton3.Text = "david"
RadioButton4.Text = "charles babbage"
cans(i) = 4
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
i=0
changestatus()
clicked = sender
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
Label1.Text = "2.Expand IDE"
RadioButton1.Text = "Intermediate development environment"
RadioButton2.Text = "Integrated development environment"
RadioButton3.Text = "Integrated development environment"

26
RadioButton4.Text = "Integrating development environment"

cans(i) = 3
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
i=0
changestatus()
clicked = sender
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
Label1.Text = "3.get current date using"
RadioButton1.Text = "Now"
RadioButton2.Text = "Date value"
RadioButton3.Text = "Date add"
RadioButton4.Text = "Date"
cans(i) = 1
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click
i=0
changestatus()
clicked = sender
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
Label1.Text = "4.Example for impact printer"
RadioButton1.Text = "Laser printer"
RadioButton2.Text = "inkjet printer"
RadioButton3.Text = "Dot matrix printer"
RadioButton4.Text = "Photo printer"
cans(i) = 3
End Sub

27
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
i=4
changestatus()
clicked = sender
Label2.Text = "5.Keyboard shortcut key to select the entire document in
ms word"
With ComboBox1.Items
.Add("ctrl+c")
.Add("ctrl+v")
.Add("ctrl+A")
.Add("ctrl+k")
End With
cans(i) = 3
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles


Button6.Click
MsgBox("your score is" & score)
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles


Button7.Click
score = 0
GroupBox1.Visible = False
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles


Button8.Click
End
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles


Button9.Click
clicked.Enabled = False
GroupBox1.Visible = False

28
Dim os As Integer
If i < 4 Then
If RadioButton1.Checked Then os = 1
If RadioButton2.Checked Then os = 2
If RadioButton3.Checked Then os = 3
If RadioButton4.Checked Then os = 4
Else : os = ComboBox1.SelectedIndex + 1
End If
If cans(i) = os Then
score = score + 20
End If
End Sub
End Class

OUTPUT:

29
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 3: Design a VB form, to accept data from the students.


Perform the following validations:
 All entries are mandatory.
 The name should contain characters only.
 Age should be 18 or above.

When the Add button is clicked, one row gets added to the table. When the
preview button is pressed data from the table is to be displayed in a grid
view.

DESIGN VIEW:

PROGRAM CODE:

Imports System.Text.RegularExpressions
Imports System.Data.SqlClient

Public Class Form1


Dim con As SqlConnection = New SqlConnection("Data
Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\BCA-LAB.BCA-
LAB030\Documents\stud2.mdf;Integrated Security=True;Connect
Timeout=30")
30
Dim com As New SqlCommand
Dim hobbies As String = ""
Dim gender As String

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As


EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub

Private Sub ADD_Click(sender As Object, e As EventArgs) Handles ADD.Click


DataGridView1.Visible = False
If (TextBox1.Text = " ") Or Not Regex.IsMatch(TextBox1.Text, "^[a-zA-
Z\s]+$") Then
MessageBox.Show("Enter proper name")
Exit Sub
End If
Dim age As Integer = Date.Today.Year - DateTimePicker1.Value.Year
If (age < 18) Then
MessageBox.Show("age is less than 18")
Exit Sub
End If
If (RadioButton1.Checked = False And RadioButton2.Checked = False) Then
MessageBox.Show("select gender")
Exit Sub
End If
If (TextBox2.Text = " ") Then
MessageBox.Show("please specify address")
Exit Sub
End If
If (ComboBox1.SelectedIndex = -1) Then
MessageBox.Show("please select state")
Exit Sub
End If
If (CheckBox1.Checked = False And CheckBox2.Checked = False And
CheckBox3.Checked = False) Then
MessageBox.Show("Select your hobbies")
Exit Sub
End If
If (RadioButton1.Checked) Then
gender = "male"

31
Else
gender = "female"
End If
If (CheckBox1.Checked) Then hobbies = "Reading"
If CheckBox2.Checked Then hobbies += "Painting"
If CheckBox3.Checked Then hobbies += "Singing"
con.Open()
com = New SqlCommand("insert into student values('" + TextBox1.Text +
"','" + DateTimePicker1.Value.Date + "','" + gender + "','" + TextBox2.Text + "','"
+ ComboBox1.SelectedItem + "','" + hobbies + "')", con)
com.ExecuteNonQuery()
MsgBox("STUDENT DETAILS INSERTED TO DATABASE")
con.Close()
End Sub

Private Sub PREVIEW_Click(sender As Object, e As EventArgs) Handles


PREVIEW.Click
DataGridView1.Visible = True
Dim adp As SqlDataAdapter = New SqlDataAdapter("select*from student",
con)
Dim ds As DataSet = New DataSet
adp.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
End
End Sub

Private Sub CLEAR_Click(sender As Object, e As EventArgs) Handles


CLEAR.Click
TextBox1.Clear()
TextBox2.Clear()
DateTimePicker1.Value = Today
RadioButton1.Checked = False
RadioButton2.Checked = False
ComboBox1.SelectedIndex = -1
CheckBox1.Checked = False

32
CheckBox2.Checked = False
CheckBox3.Checked = False
End Sub
End Class

OUTPUT:

33
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 4: Design the following VB that accepts the author‟s name,title


and price from the user and stores the same in the database.When the add
button is pressed,an empty row is created in the database, when the save
button is prtessed the data is to be stored in the database. The delete button
will delete the current record. Perform navigation if the database contains
one or more records. All data is mandatory for saving. Price must be
numeric and greater than zero.

DESIGN VIEW:

PROGRAM CODE:

Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds, ds1 As New DataSet
Dim bds As New BindingSource
Dim dr As SqlDataReader
Dim str As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load

34
Dim constr As String = "Data
Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\BCA-LAB.BCA-
LAB030\Documents\author.mdf;Integrated Security=True;Connect
Timeout=30"
con.ConnectionString = constr
da = New SqlDataAdapter("select* from Book", con)
da.Fill(ds, "table1")
bds.DataSource = ds
bds.DataMember = "table1"
TextBox1.DataBindings.Add("text", bds, "Author'sName")
TextBox2.DataBindings.Add("text", bds, "Title")
TextBox3.DataBindings.Add("text", bds, "Price")
End Sub

Private Sub TextBox3_KeyPress(sender As Object, e As KeyPressEventArgs)


Handles TextBox3.KeyPress
If Asc(e.KeyChar) <> 8 And (e.KeyChar) <> " " Then
If (e.KeyChar) < "0" Or (e.KeyChar) > "9" Then
e.Handled = True
End If
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles


Button9.Click
bds.Position = bds.Count - 1
If bds.Position = bds.Count - 1 Then
MsgBox("last record")
End If
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles


Button6.Click

35
If bds.Position = 0 Then
MsgBox("first record")
End If
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles


Button7.Click
bds.Position -= 1
If bds.Position = 0 Then
MsgBox("no previous record")
End If
bds.Position = 0
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox1.Focus()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
If TextBox1.Text = " " Or TextBox2.Text = " " Or TextBox3.Text = " " Then
MsgBox("fill all the entries")
Exit Sub
ElseIf TextBox3.Text <= 0 Then
MsgBox("price must be>0")
Else
cmd.CommandText = "insert into Book values(' " + TextBox1.Text + " ',' "
+ TextBox2.Text + " '," + TextBox3.Text + ")"
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
MsgBox("record inserted")
End If
End Sub

36
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
con.Close()
str = InputBox("Enter the title to be deleted")
cmd.CommandText = "select*from Book where title=' " + str + " '"
cmd.Connection = con
con.Open()
dr = cmd.ExecuteReader()
dr.Read()
If dr.HasRows Then
con.Close()
cmd.CommandText = "delete from Book where title=' " + str + " ' "
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("record deleted")
Else
MsgBox("no record")
End If
End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles


Button8.Click
bds.Position += 1
If bds.Position = bds.Count - 1 Then
MsgBox("last record")
End If
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


Button5.Click
ds1.Clear()
da.Fill(ds1)
DataGridView1.DataSource = ds1.Tables(0)
End Sub
End Class

37
OUTPUT:

38
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 5: Create a web form of or login module which adds a


username and password to the database. The username in the database
should be ptimary key.

DESIGN VIEW:

PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

39
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\BCA-
LAB\Documents\webapplication4.mdf;Integrated Security=True;Connect
Timeout=30");
SqlCommand cmd =new SqlCommand();
cmd.Connection=con;
cmd.CommandText="insert into users
values('"+TextBox1.Text+"','"+TextBox2.Text+"')";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript
(this,GetType(),"showalert","alert('login successful');",true);
TextBox1.Text="";
TextBox2.Text="";
}

protected void Button2_Click(object sender, EventArgs e)


{
TextBox1.Text = "";
TextBox2.Text = "";
}

}
}

40
OUTPUT:

41
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM 6: Create a web application to insert records into a database
table having the following fields ( EmpId, EmpName, DeptName, Salary).
Update any employee's salary and increment it to 15% of the present
salary. Perform the delete operation on 1 row of the database table.

DESIGN VIEW:

PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace EMPLOYEE1
{
public partial class WebForm1 : System.Web.UI.Page
{

protected void Button1_Click(object sender, EventArgs e)

42
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\v11.0;AttachDbFilename=C:\Rakshitha\EMPLOYEE1\EMPLO
YEE1\App_Data\DatabaseEMP.mdf;Integrated Security=True");
SqlCommand cmd;
string str = "insert into emp values('" + TextBox1.Text + "','" +
TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + ")";
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Label1.Text = "User Added";
GridView1.DataBind();
}
}
}

43
OUTPUT:

44
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************

PROGRAM 7: Create a ASP .NET web application with the above


interface and if user clicks on “Search” button then following operation has
to be done,From the Given two strings (from input1 and input2), return a
new string, following the rules given below. If string b occurs in string a,
then the new string should concatenate the characters that appear before
and after of String b.Ignore cases where there is no character before or
after the word, and a character may be included twice if it is in between
two string b's.

Example1)

i/p) abcdefcdhycd,cd

o/p) befhy

Example2)

i/p) kumarkumar,kum

o/p) ara

If user clicks on “Construct” button then following operation has to be


performed from Given two strings print a new string which is made of the
following combination-first character of a, the first character of b, second
character of a, second character of b and so on. Any characters left will go
to the end of the result. Example1) i/p:Hello,World o/p:Hweolrllod in both
the operation output should be displayed in output text box and clear
button should clear all the text boxes.

45
PROGRAM CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Text.RegularExpressions;

namespace Search
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void TextBox3_TextChanged(object sender, EventArgs e)


{

protected void btnsearch_Click(object sender, EventArgs e)


{
string str1 = txtInput1.Text;
string str2 = txtInput2.Text;
StringBuilder sb = new StringBuilder();
Regex reg = new Regex(str2, RegexOptions.IgnoreCase);
foreach (string s in reg.Split(str1))
{
sb.Append(s);
}

46
textOutput.Text = sb.ToString();
}

protected void btnconstruct_Click(object sender, EventArgs e)


{
string str1 = txtInput1.Text;
string str2 = txtInput2.Text;
StringBuilder sb = new StringBuilder();
int i = 0;
foreach (char c in str1)
{
sb.Append(c);
while (i < str2.Length)
{
sb.Append(str2[i]);
i++;
break;
}
}
textOutput.Text = sb.ToString();
}

protected void btnclear_Click(object sender, EventArgs e)


{
txtInput1.Text = string.Empty;
txtInput2.Text = string.Empty;
textOutput.Text = string.Empty;
txtInput1.Focus();
}
}
}

47
OUTPUT:

48

You might also like