0% found this document useful (0 votes)
353 views58 pages

Practical Slip

The document contains examples of code snippets for various programming tasks in VB.NET and C#.NET. It includes programs to display timer, accept employee details and store in database, move text from left to right, create classes and functions, pick date from datetime picker, perform database operations, check vowel/consonant, calculate interest, and more. The examples provide code solutions to accomplish common programming tasks.

Uploaded by

aswinidwivedi1
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)
353 views58 pages

Practical Slip

The document contains examples of code snippets for various programming tasks in VB.NET and C#.NET. It includes programs to display timer, accept employee details and store in database, move text from left to right, create classes and functions, pick date from datetime picker, perform database operations, check vowel/consonant, calculate interest, and more. The examples provide code solutions to accomplish common programming tasks.

Uploaded by

aswinidwivedi1
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/ 58

Dot Net Framework

PRACTICAL SLIP

SLIP NO 1
A) Write a VB.Net Program to display the numbers continuously in TextBox by

clicking on Button.

Answer :

Public Class Form1

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

TextBox1.Text = Second(DateTime.Now)

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

Timer1.Enabled = True

Timer1.Interval = 1000

Timer1.Start()

End Sub

End Class
Output :

B) Write a VB.Net program to accept the details of Employee (ENO, EName Salary)

and store it into the database and display it on gridview control.

Answer :

Imports System

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Desktop\New folder\Emp.accdb")

Dim adpt As New OleDbDataAdapter("Select * from Emp", con)

Dim ds As New DataSet

Dim cmd As New OleDbCommand

Public Function display()

adpt.Fill(ds, "Emp")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "Emp"
Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into Emp values(" & TextBox1.Text & ",'" &
TextBox2.Text & "'," & TextBox3.Text & ")"

con.Open()

cmd.ExecuteNonQuery()

con.Close()

ds.Clear()

display()

End Sub

End Class

Output :
SLIP NO 2

A) Write a Vb.Net program to move the Text “Pune University” continuously from Left

to Right and Vice Versa.

Answer :

Public Class Form1

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

If Label1.Left >= Me.Width Then

Label1.Left = -100
Else

Label1.Left = Label1.Left + 10

End If

End Sub

End Class

Output :

B)Write a C#.Net program to create a base class Department and derived classes Sales and

Human Resource. Accept the details of both departments and display them in proper

format.

Answer :

Output :

SLIP NO 3

A) Write a program in C# .Net to create a function for the sum of two numbers.
Answer :

namespace WinFormsApp18

public partial class Form1 : Form

public Form1()

InitializeComponent();

public static int Sum(int a, int b)

return a + b;

private void button1_Click(object sender, EventArgs e){

int a = Convert .ToInt32 (textBox1.Text);

int b = Convert .ToInt32 (textBox2.Text);

int c = Sum (a, b);

label5.Text = c.ToString();

Output :
B) Write a VB.NET program to create teacher table (Tid, TName, subject) Insert the

records (Max: 5). Search record of a teacher whose name is “Seeta” and display result.

Answer :

Imports System

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\teacher.accdb")

Dim adpt As New OleDbDataAdapter("Select * from teacher", con)

Dim cmd As New OleDbCommand

Dim ds As New DataSet


Public Function display()

adpt.Fill(ds, "teacher")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "teacher"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into teacher values(" & TextBox1.Text & ",'" &
TextBox2.Text & "','" & TextBox3.Text & "')"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Inserted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

Private Sub TextBox4_KeyDown(sender As Object,


e As KeyEventArgs) Handles TextBox4.KeyDown

ds.Clear()

Dim adp As New OleDbDataAdapter("select * from teacher Where Name like


'%" & TextBox4.Text & "%'", con)
adp.Fill(ds, "search")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "search"

End Sub

End Class

Output :

SLIP NO 4

A) Design a VB.net form to pick a date from DateTimePicker Control and display day,

month and year in separate text boxes.

Answer :

Public Class Form1


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

Label1.Text = "Year : " & DateTimePicker1.Value.Year

Label2.Text = "Month : " & DateTimePicker1.Value.Month

Label3.Text = "Day : " & DateTimePicker1.Value.Day

End Sub

End Class

Output :

B) Create a web application to insert 3 records inside the SQL database table having

following fields ( DeptId, DeptName, EmpName, Salary). Update the salary for any one

employee and increment it to 15% of the present salary. Perform delete operation on

one row of the database table.

Answer :

Output :

SLIP NO 5

A) Write a VB.NET program to accept a character from keyboard and check whether it

is vowel or consonant. Also display the case of that character.

Answer :

Public Class Form1

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

Dim a As Char

Dim str As String

a = TextBox1.Text
If (TextBox1.Text.Length <= 1) Then

If Char.IsUpper(a) Then

str = "Upper Case"

Else

str = "Lower Case"

End If

If (a = "a" Or a = "e" Or a = "i" Or a = "o" Or a = "u" Or

a = "A" Or a = "E" Or a = "I" Or a = "O" Or a = "U") Then

MessageBox.Show(TextBox1.Text & " is " & str & " Vowel")

Else

MessageBox.Show(TextBox1.Text & " is " & str & " Consonant")

End If

End If

End Sub

Private Sub TextBox1_Leave(sender As Object,


e As EventArgs) Handles TextBox1.Leave

Dim a As String

a = TextBox1.Text

If (TextBox1.Text.Length > 1) Then

Label2.Text = "Only One Characters Allowed...!"

Else

Label2.Text = ""

End If

End Sub

End Class
Output :

B) Design a web application form in ASP.Net having loan amount, interest rate and

duration fields. Calculate the simple interest and perform necessary validation i.e.

Ensures data has been entered for each field. Checking for non-numeric value. Assume

suitable web-form controls and perform necessary validation.

Answer :

Output :

SLIP NO 6

A) Write ASP.Net program that displays the names of some flowers in two columns.

Bind a label to the RadioButtonList so that when the user selects an option from the list
and clicks on a button, the label displays the flower selected by the user.

Answer :

Output :

B) Write a VB.NET program to create movie table (Mv_Name, Release_year,

Director). Insert the records (Max: 5). Delete the records of movies whose release year

is 2022 and display appropriate message in message box.

Answer :

Imports System

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\movie.accdb")

Dim adpt As New OleDbDataAdapter("Select * from movie", con)

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

adpt.Fill(ds, "movie")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "movie"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

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

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into movie values('" & TextBox1.Text & "'," &
TextBox2.Text & ",'" & TextBox3.Text & "')"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Inserted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

Private Sub Button2_Click(sender As Object,


e As EventArgs) Handles Button2.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "DELETE FROM movie WHERE Release_year = " &


TextBox2.Text

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Deleted Successfully...!")

End If

con.Close()

ds.Clear()

display()
End Sub

End Class

Output :

SLIP NO 7

A) Write a ASP.Net program to accept a number from the user in a textbox control and

throw an exception if the number is not a perfect number. Assume suitable controls on

the web form.

Answer :

Output :

B) Write a VB.NET program to create a table student (Roll No, SName, Class,City).

Insert the records (Max: 5). Update city of students to ‘Pune’ whose city is ‘Mumbai’
and display updated records in GridView.

Answer :

Output :

SLIP NO 8

A) List of employees is available in listbox. Write ASP.Net application to add

selected or all records from listbox to Textbox (assume multi-line property of textbox is

true).

Answer :

Output :

B) Write a c#.Net program for multiplication of matrices.

Answer :

Output :

SLIP NO 9

A) Write a Menu driven program in C#.Net to perform following functionality:

Addition, Multiplication, Subtraction, Division.

Answer :

namespace WinFormsApp18

public partial class Form1 : Form

public Form1()

{
InitializeComponent();

private void addtionToolStripMenuItem_Click(object sender, EventArgs e)

int a = Convert.ToInt32(textBox1.Text);

int b = Convert.ToInt32(textBox2.Text);

int c = a+b;

label3.Text = "+";

label5.Text = c.ToString();

private void substractionToolStripMenuItem_Click(object sender, EventArgs


e)

int a = Convert.ToInt32(textBox1.Text);

int b = Convert.ToInt32(textBox2.Text);

int c = a - b;

label3.Text = "-";

label5.Text = c.ToString();

private void divisonToolStripMenuItem_Click(object sender, EventArgs e)

int a = Convert.ToInt32(textBox1.Text);

int b = Convert.ToInt32(textBox2.Text);

int c = a / b;

label3.Text = "/";
label5.Text = c.ToString();

private void multiplicationToolStripMenuItem_Click(object sender,


EventArgs e)

int a = Convert.ToInt32(textBox1.Text);

int b = Convert.ToInt32(textBox2.Text);

int c = a * b;

label3.Text = "*";

label5.Text = c.ToString();

Output :
B) Create an application in ASP.Net that allows the user to enter a number in the

textbox named "getnum". Check whether the number in the textbox "getnum" is

palindrome or not. Print the message accordingly in the label control named lbldisplay

when the user clicks on the button "check".

Answer :

Output :

SLIP NO 10

A) Write a program that demonstrates the use of primitive data types in C#. The

program should also support the type conversion of :

● Integer to String

● String to Integer

Answer :

namespace WinFormsApp19

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

{
int num = Convert.ToInt32(textBox1.Text);

label1.Text = "Before conversion : " + num.GetType();

String str = Convert.ToString(num);

label2.Text = "After conversion: " + str.GetType();

private void button2_Click(object sender, EventArgs e)

label1.Text = "Before conversion : " + textBox1.Text.GetType();

int num = Convert.ToInt32(textBox1.Text);

label2.Text = "After conversion: " + num.GetType();

Output :
B) Write ASP.Net program to connect to the master database in SQL Server in the

Page_Load event. When the connection is established, the message “Connection has

been established” should be displayed in a label in the form .

Answer :

Output :

SLIP NO 11

A) Write a ASP.Net program that gets user input such as the user name, mode of

payment, appropriate credit card. After the user enters the appropriate values the

Validation button validates the values entered.

Answer :

Output :
B) Write C# program to make a class named Fruit with a data member to calculate the

number of fruits in a basket. Create two other class named Apples and Mangoes to

calculate the number of apples and mangoes in the basket. Display total number of

fruits in the basket.

Answer :

Output :

SLIP NO 12

A) Write ASP.Net program that displays a button in green color and it should change

into yellow when the mouse moves over it.

Answer :

Output :

B) Write a VB.NET program to create player table (PID, PName, Game,

no_of_matches). Insert records and update number of matches of ‘Rohit Sharma’ and

display result in data grid view.

Answer :

Imports System

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\player.accdb")

Dim adpt As New OleDbDataAdapter("Select * from player", con)


Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

adpt.Fill(ds, "player")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "player"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into player values(" & TextBox1.Text & ",'" &
TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Inserted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

Private Sub Button2_Click(sender As Object,


e As EventArgs) Handles Button2.Click

cmd.Connection = con
cmd.CommandType = CommandType.Text

cmd.CommandText = "UPDATE player SET no_of_matches = " & TextBox4.Text


& " WHERE PName = '" & TextBox2.Text & "'"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Updated Successfully...!")

End If

con.Close()

con.Close()

ds.Clear()

display()

End Sub

End Class

Output :

SLIP NO 13
A) Write a VB.net program for blinking an image.

Answer :

Public Class Form1

Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick

If PictureBox1.Visible Then

PictureBox1.Visible = False

Else

PictureBox1.Visible = True

End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Timer1.Enabled = True

Timer1.Interval = 1000

Timer1.Start()

End Sub

End Class

Output :

B) Write a C# Program to accept and display ‘n’ student’s details such as Roll. No,

Name, marks in three subjects, using class. Display percentage of each student.

Answer :

Output :

SLIP NO 14
A) Write a VB.net program for blinking an image.
Answer :

Public Class Form1

Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick

If PictureBox1.Visible Then

PictureBox1.Visible = False

Else

PictureBox1.Visible = True

End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Timer1.Enabled = True

Timer1.Interval = 1000

Timer1.Start()

End Sub

End Class

Output :
B) Write a C# Program to accept and display ‘n’ student’s details such as Roll. No,

Name, marks in three subjects, using class. Display percentage of each student.

Answer :

Output :

SLIP NO 15

A) Write ASP.Net application to create a user control that contains a list of colors. Add

a button to the Web Form which when clicked changes the color of the form to the

color selected from the list.

Answer :

Public Class Form1

Private Sub RedToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles RedToolStripMenuItem.Click

Me.BackColor = Color.Red

End Sub
Private Sub GreenToolStripMenuItem_Click(sender As Object,
e As EventArgs) Handles GreenToolStripMenuItem.Click

Me.BackColor = Color.Green

End Sub

Private Sub BlueToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles BlueToolStripMenuItem.Click

Me.BackColor = Color.Blue

End Sub

End Class

Output :

B) Write a C#.Net Program to accept and display ‘n’ customer’s details such as

customer_no, Name, address ,itemno, quantity price . Display total price of all item.

Answer :

Output :
SLIP NO 16

A) Write ASP.Net program to create a user control that receives the user name and

password from the user and validates them. If the user name is "DYP" and the password

is "Pimpri", then the user is authorized, otherwise not.

Answer :

Output :

B) Define a class supplier with fields – sid, name, address, pincode. Write a C#.Net

Program to accept the details of ‘n’ suppliers and display it.


Answer :

Output :

SLIP NO 17

A) Write a C#.Net application to display the vowels from a given String.

Answer :

namespace WinFormsApp21

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

String str = (textBox1.Text);

char[] chars = str.ToCharArray();

for (int i = 0; i < chars.Length; i++)

switch (chars[i])

case 'A' or 'a':

listBox1.Items.Add(chars[i].ToString());

break;
case 'E' or 'e':

listBox1.Items.Add(chars[i].ToString());

break;

case 'I' or 'i':

listBox1.Items.Add(chars[i].ToString());

break;

case 'O' or 'o':

listBox1.Items.Add(chars[i].ToString());

break;

case 'U' or 'u':

listBox1.Items.Add(chars[i].ToString());

break;

Output :
B) Write a VB.NET program to accept the details of product (PID, PName,

expiry_date, price). Store it into the database and display it on data grid view.

Answer :

Imports System

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\product.accdb")

Dim adpt As New OleDbDataAdapter("Select * from product", con)

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

adpt.Fill(ds, "product")

DataGridView1.DataSource = ds
DataGridView1.DataMember = "product"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into product values(" & TextBox1.Text & ",'" &
TextBox2.Text & "','" & DateTimePicker1.Value & "'," & TextBox4.Text & ")"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Inserted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

End Class

Output :
SLIP NO 18

A) Write a VB.NET program to accept a number from user through input box and

display its multiplication table into the list box.

Answer :

Public Class Form1

Dim a As Integer

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

Dim a As Integer

a = TextBox1.Text

For b = 1 To 10

ListBox1.Items.Add(a * b)

Next

Console.ReadLine()
End Sub

End Class

Output :

B) Write ASP.Net program containing the following controls:

• ListBox

• Button

• Image

• Label

The listbox is used to list items available in a store. When the user clicks on an

item in the listbox, its image is displayed in the image control. When the user clicks the

button, the cost of the selected item is displayed in the control.

Answer :

Output :

SLIP NO 19

A) Write a VB.NET program to check whether enter string is palindrome or not.

Answer :

Public Class Form1

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

Dim str, rev As String

str = TextBox1.Text

rev = StrReverse(str)
If (str = rev) Then

MessageBox.Show("String is Palindrome : " & str)

Else

MessageBox.Show("String is Not Palindrome : " & str)

End If

End Sub

End Class

Output :

B) "How is the book ASP.NET with C# by Wrox publication?"

Give the user three choices :

i)Good ii)Satisfactory iii)Bad.

Provide a VOTE button. After user votes, present the result in percentage using labels

next to the choices.

Answer :

Output :

SLIP NO 20

A) Write a VB.NET program to generate Sample Tree View control.

Answer :

Public Class Form1

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

TreeView1.Nodes.Add("Master")

TreeView1.Nodes(0).Nodes.Add("Student Details")

TreeView1.Nodes(0).Nodes.Add("Teacher Details")
TreeView1.Nodes.Add("Examination")

TreeView1.Nodes(1).Nodes.Add("Internal Exam")

TreeView1.Nodes(1).Nodes.Add("External Exam")

TreeView1.Nodes(1).Nodes.Add("Practical Exam")

End Sub

End Class

Output :

B) Write a Web application in ASP.Net that generates the “IndexOutOfRange”

exception when a button is clicked. Instead of displaying the above exception, it

redirects the user to a custom error page. All the above should be done with the trace

for the page being enabled.

Answer :

Output :
SLIP NO 21

A) Write a VB.NET program to accept sentences in text box and count the number of

words and display the count in message box.

Answer :

Public Class Form1

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

Dim str As String

str = TextBox1.Text

Dim I, Count As Integer

Dim arr() As Char = str.ToCharArray

For I = 0 To arr.Length - 1

If arr(I) = " " Then

Count = Count + 1

End If

Next

MsgBox(Count + 1 & " words")

End Sub

End Class

Output :

B) Write ASP.Net application for the following:

1. Create a table EMP(eno, ename, edesignation, salary, joindate)

2. Insert a Record.

3. Update a record

Answer :

Output :
SLIP NO 22

A) Write a program in C# to create a function to swap the values of two integers.

Answer :

Output :

B) Write a Vb.net program to design the following form; it contains the three menus

Color (Red, Blue, and Green), Window (Maximize, Minimize, and Restore) and Exit.

On Selection of any menu or submenu result should affect the form control( for

example if user selected Red color from Color menu back color of form should get

changed to Red and if user selected Maximize from Window Menu then form should

get maximized).

Answer :

Public Class Form1

Private Sub RedToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles RedToolStripMenuItem.Click

Me.BackColor = Color.Red

End Sub

Private Sub GreenToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles GreenToolStripMenuItem.Click

Me.BackColor = Color.Green

End Sub

Private Sub BlueToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue

End Sub

Private Sub MaximizeToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles MaximizeToolStripMenuItem.Click

Me.WindowState = FormWindowState.Maximized

End Sub

Private Sub MiniMToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles MiniMToolStripMenuItem.Click

Me.WindowState = FormWindowState.Minimized

End Sub

Private Sub RestoreToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles RestoreToolStripMenuItem.Click

Me.WindowState = FormWindowState.Normal

End Sub

End Class

Output :
SLIP NO 23

A) Write a program in C# to create a function to display the n terms of Fibonacci

sequence.

Answer :

namespace WinFormsApp22

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)


{

int a, b=0, c=1, d;

a = Convert.ToInt32(textBox1.Text);

listBox1.Items.Add(b);

listBox1.Items.Add(c);

for (int i = 0; i < a; i++)

d = b + c;

listBox1.Items.Add(d);

b = c;

c = d;

Output :
B) Create the application in ASP.Net that accepts name, password ,age , email id, and

user id. All the information entry is compulsory. Password should be reconfirmed. Age

should be within 21 to 30. Email id should be valid. User id should have at least a

capital letter and digit as well as length should be between 7 and 20 characters.

Answer :

Output :

SLIP NO 24

A) Write a program in C#.Net to create a function to check whether a number is prime or

not.

Answer :

namespace WinFormsApp26

public partial class Form1 : Form

public Form1()

InitializeComponent();

public static String prime(int a)

Boolean isprime = true;

int b = a/2;

for(int i = 2; i <= b; i++)

{
if(a % 2 == 0)

isprime = false;

break;

if (isprime)

return a + " is Prime Number";

else

return a + " is Not Prime Number";

private void button1_Click(object sender, EventArgs e)

MessageBox.Show(prime(Convert.ToInt32(textBox1.Text)));

Output :
B) Write a VB.NET program to create Author table (aid, aname, book_ name). Insert the

records (Max 5). Delete a record of author who has written “VB.NET book” and

display remaining records on the data grid view. (Use MS Access to create db.)

Answer :

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\Author.accdb")

Dim adpt As New OleDbDataAdapter("Select * from Author", con)

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

adpt.Fill(ds, "Author")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "Author"
Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into Author values(" & TextBox1.Text & ",'" &
TextBox2.Text & "','" & TextBox3.Text & "')"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Inserted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

Private Sub Button2_Click(sender As Object,


e As EventArgs) Handles Button2.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "DELETE FROM Author WHERE book_name='" & TextBox3.Text


& "'"

con.Open()

If cmd.ExecuteNonQuery() Then
MessageBox.Show("Deleted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

End Class

Output :

SLIP NO 25

A) Write a program in C#.Net to create a function to calculate the sum of the individual
digits of a given number.

Answer :

Output :

B) Create a Web Application in ASP.Net to display all the Empname and Deptid of the

employee from the database using SQL source control and bind it to GridView.

Database fields are(DeptId, DeptName, EmpName, Salary).

Create Table Alter Table Drop Table Type Your DDL Query Here

Answer :

Output :

SLIP NO 26

A). Write a program in C#.Net to create a recursive function to find the factorial of a

given number

Answer :

Output :

B) Write a ASP.Net program to create a Login Module which adds Username and

Password in the database. Username in the database should be a primary key.

Answer :

Output :

SLIP NO 27

A) Write a program in C#.Net to find the length of a string.

Answer :
namespace WinFormsApp24

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

int a = textBox1.Text.Length;

MessageBox.Show("Length : " + a);

Output :
B) Create a web application in ASP.Net which may have a textbox. Now user must type

some data into it, the data he can enter is only 255 characters. After he crosses the limit

then the last word should not by typed and at the same time color of textbox

should be red.

Answer :

Output :

SLIP NO 28

A) Write a program in C#.Net to read n numbers in an array and display it in reverse

order.

Answer :

namespace WinFormsApp23

public partial class Form1 : Form


{

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

listBox1.Items.Add(textBox1.Text);

private void button2_Click(object sender, EventArgs e)

listBox2.Items.Clear();

for (int i = listBox1.Items.Count-1; i >= 0; i--)

listBox2.Items.Add (listBox1.Items[i]);

Output :
B) Write a VB.NET program to create a table Patient (PID, PName, Contact No,

Disease). Insert five records into table and display appropriate message in message box.

ENo EName Salary

Answer :

Output :

SLIP NO 29

A) Write a program in C#.Net to separate the individual characters from a String.

Answer :

using System;

class Program {

static void Main(string[] args) {

string inputString = "Hello, world!";


char[] characters = inputString.ToCharArray();

Console.WriteLine("Individual characters from the string: ");

foreach (char c in characters) {

Console.Write(c + " ");

Console.ReadLine();

Output :

B) Write a VB.NET program to accept the details of customer (CName, Contact No,

Email_id). Store it into the database with proper validation and display appropriate

message by using Message box.

Answer :

Imports System.Data.SqlClient

Public Class CustomerForm

' Database connection string

Dim connectionString As String = "Data


Source=localhost\SQLEXPRESS;Initial Catalog=TestDB;Integrated
Security=True"
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles
btnSave.Click

' Get the customer details from textboxes

Dim cname As String = txtName.Text.Trim()

Dim contactNo As String = txtContactNo.Text.Trim()

Dim email As String = txtEmail.Text.Trim()

' Validate the inputs

If cname = "" Then

MessageBox.Show("Please enter customer name.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)

Return

End If

If contactNo = "" Or Not IsNumeric(contactNo) Then

MessageBox.Show("Please enter valid contact number.",


"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Return

End If

If email = "" Or Not email.Contains("@") Then

MessageBox.Show("Please enter valid email address.", "Error",


MessageBoxButtons.OK, MessageBoxIcon.Error)

Return

End If

' Insert the customer details into the database


Using connection As New SqlConnection(connectionString)

Dim query As String = "INSERT INTO Customers (CName,


ContactNo, Email) VALUES (@CName, @ContactNo, @Email)"

Dim command As New SqlCommand(query, connection)

command.Parameters.AddWithValue("@CName", cname)

command.Parameters.AddWithValue("@ContactNo", contactNo)

command.Parameters.AddWithValue("@Email", email)

connection.Open()

Dim rowsAffected As Integer = command.ExecuteNonQuery()

connection.Close()

If rowsAffected > 0 Then

MessageBox.Show("Customer details saved


successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Informati
on)

Else

MessageBox.Show("Failed to save customer


details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End If

End Using

End Sub

End Class

Output :
SLIP NO 30

A) Write a VB.NET program to design following screen, accept the details from the user. Clicking
on Submit button Net Salary should be calculated and displayed into the Textbox. Display the
Messagebox informing the Name and Net Salary of employee.

Answer :

Public Class Form1

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

Label10.Text = (Int(TextBox2.Text) + Int(TextBox3.Text) + Int(TextBox4.Text)


+ Int(TextBox5.Text) + Int(TextBox6.Text) + Int(TextBox7.Text) +
Int(TextBox8.Text))

Label12.Text = Int(TextBox6.Text) + Int(TextBox7.Text) + Int(TextBox8.Text)

Label14.Text = Label10.Text - Label12.Text

MessageBox.Show("Employee Name : " & TextBox1.Text & Environment.NewLine


& "Total Salary is : " & Label14.Text)

End Sub

Private Sub TextBox2_Leave(sender As Object,


e As EventArgs) Handles TextBox2.Leave

TextBox3.Text = (TextBox2.Text * 31) / 100

TextBox4.Text = (TextBox2.Text * 9) / 100

End Sub

End Class

Output :
B) Write a VB.NET program to accept the details Supplier (SupId, SupName, Phone

No, Address) store it into the database and display it.

Answer :

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\Supplier.accdb")

Dim adpt As New OleDbDataAdapter("Select * from Supplier", con)

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

adpt.Fill(ds, "Supplier")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "Supplier"

Return ds
End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles Button1.Click

cmd.Connection = con

cmd.CommandType = CommandType.Text

cmd.CommandText = "insert into Supplier values(" & TextBox1.Text & ",'" &
TextBox2.Text & "'," & TextBox3.Text & ",'" & TextBox4.Text & "')"

con.Open()

If cmd.ExecuteNonQuery() Then

MessageBox.Show("Inserted Successfully...!")

End If

con.Close()

ds.Clear()

display()

End Sub

End Class

Output :

You might also like