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

VB.Net Programming Practical Exercises

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)
926 views58 pages

VB.Net Programming Practical Exercises

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

Dot Net Framework

PRACTICAL SLIP

SLIP NO 1
A) Write a [Link] 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 [Link]

[Link] = Second([Link])

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = True

[Link] = 1000

[Link]()

End Sub

End Class
Output :

B) Write a [Link] 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 [Link]

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Desktop\New folder\[Link]")

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

Dim ds As New DataSet

Dim cmd As New OleDbCommand

Public Function display()

[Link](ds, "Emp")

[Link] = ds

[Link] = "Emp"
Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into Emp values(" & [Link] & ",'" &
[Link] & "'," & [Link] & ")"

[Link]()

[Link]()

[Link]()

[Link]()

display()

End Sub

End Class

Output :
SLIP NO 2

A) Write a [Link] 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 [Link]

If [Link] >= [Link] Then

[Link] = -100
Else

[Link] = [Link] + 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 ([Link]);

int b = Convert .ToInt32 ([Link]);

int c = Sum (a, b);

[Link] = [Link]();

Output :
B) Write a [Link] 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 [Link]

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\[Link]")

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

Dim cmd As New OleDbCommand

Dim ds As New DataSet


Public Function display()

[Link](ds, "teacher")

[Link] = ds

[Link] = "teacher"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into teacher values(" & [Link] & ",'" &
[Link] & "','" & [Link] & "')"

[Link]()

If [Link]() Then

[Link]("Inserted Successfully...!")

End If

[Link]()

[Link]()

display()

End Sub

Private Sub TextBox4_KeyDown(sender As Object,


e As KeyEventArgs) Handles [Link]

[Link]()

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


'%" & [Link] & "%'", con)
[Link](ds, "search")

[Link] = ds

[Link] = "search"

End Sub

End Class

Output :

SLIP NO 4

A) Design a [Link] 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 [Link]

[Link] = "Year : " & [Link]

[Link] = "Month : " & [Link]

[Link] = "Day : " & [Link]

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 [Link] 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 [Link]

Dim a As Char

Dim str As String

a = [Link]
If ([Link] <= 1) Then

If [Link](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

[Link]([Link] & " is " & str & " Vowel")

Else

[Link]([Link] & " is " & str & " Consonant")

End If

End If

End Sub

Private Sub TextBox1_Leave(sender As Object,


e As EventArgs) Handles [Link]

Dim a As String

a = [Link]

If ([Link] > 1) Then

[Link] = "Only One Characters Allowed...!"

Else

[Link] = ""

End If

End Sub

End Class
Output :

B) Design a web application form in [Link] 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 [Link] 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 [Link] 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 [Link]

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\[Link]")

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

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

[Link](ds, "movie")

[Link] = ds

[Link] = "movie"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub
Private Sub Button1_Click(sender As Object,
e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into movie values('" & [Link] & "'," &
[Link] & ",'" & [Link] & "')"

[Link]()

If [Link]() Then

[Link]("Inserted Successfully...!")

End If

[Link]()

[Link]()

display()

End Sub

Private Sub Button2_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "DELETE FROM movie WHERE Release_year = " &


[Link]

[Link]()

If [Link]() Then

[Link]("Deleted Successfully...!")

End If

[Link]()

[Link]()

display()
End Sub

End Class

Output :

SLIP NO 7

A) Write a [Link] 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 [Link] 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 [Link] 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([Link]);

int b = Convert.ToInt32([Link]);

int c = a+b;

[Link] = "+";

[Link] = [Link]();

private void substractionToolStripMenuItem_Click(object sender, EventArgs


e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

int c = a - b;

[Link] = "-";

[Link] = [Link]();

private void divisonToolStripMenuItem_Click(object sender, EventArgs e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

int c = a / b;

[Link] = "/";
[Link] = [Link]();

private void multiplicationToolStripMenuItem_Click(object sender,


EventArgs e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

int c = a * b;

[Link] = "*";

[Link] = [Link]();

Output :
B) Create an application in [Link] 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([Link]);

[Link] = "Before conversion : " + [Link]();

String str = [Link](num);

[Link] = "After conversion: " + [Link]();

private void button2_Click(object sender, EventArgs e)

[Link] = "Before conversion : " + [Link]();

int num = Convert.ToInt32([Link]);

[Link] = "After conversion: " + [Link]();

Output :
B) Write [Link] 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 [Link] 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 [Link] 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 [Link] 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 [Link]

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\[Link]")

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


Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

[Link](ds, "player")

[Link] = ds

[Link] = "player"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into player values(" & [Link] & ",'" &
[Link] & "','" & [Link] & "'," & [Link] & ")"

[Link]()

If [Link]() Then

[Link]("Inserted Successfully...!")

End If

[Link]()

[Link]()

display()

End Sub

Private Sub Button2_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con
[Link] = [Link]

[Link] = "UPDATE player SET no_of_matches = " & [Link]


& " WHERE PName = '" & [Link] & "'"

[Link]()

If [Link]() Then

[Link]("Updated Successfully...!")

End If

[Link]()

[Link]()

[Link]()

display()

End Sub

End Class

Output :

SLIP NO 13
A) Write a [Link] program for blinking an image.

Answer :

Public Class Form1

Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles [Link]

If [Link] Then

[Link] = False

Else

[Link] = True

End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

[Link] = True

[Link] = 1000

[Link]()

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 [Link] program for blinking an image.
Answer :

Public Class Form1

Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles [Link]

If [Link] Then

[Link] = False

Else

[Link] = True

End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

[Link] = True

[Link] = 1000

[Link]()

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 [Link] 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 [Link]

[Link] = [Link]

End Sub
Private Sub GreenToolStripMenuItem_Click(sender As Object,
e As EventArgs) Handles [Link]

[Link] = [Link]

End Sub

Private Sub BlueToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = [Link]

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 [Link] 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 = ([Link]);

char[] chars = [Link]();

for (int i = 0; i < [Link]; i++)

switch (chars[i])

case 'A' or 'a':

[Link](chars[i].ToString());

break;
case 'E' or 'e':

[Link](chars[i].ToString());

break;

case 'I' or 'i':

[Link](chars[i].ToString());

break;

case 'O' or 'o':

[Link](chars[i].ToString());

break;

case 'U' or 'u':

[Link](chars[i].ToString());

break;

Output :
B) Write a [Link] 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 [Link]

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\[Link]")

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

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

[Link](ds, "product")

[Link] = ds
[Link] = "product"

Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into product values(" & [Link] & ",'" &
[Link] & "','" & [Link] & "'," & [Link] & ")"

[Link]()

If [Link]() Then

[Link]("Inserted Successfully...!")

End If

[Link]()

[Link]()

display()

End Sub

End Class

Output :
SLIP NO 18

A) Write a [Link] 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 [Link]

Dim a As Integer

a = [Link]

For b = 1 To 10

[Link](a * b)

Next

[Link]()
End Sub

End Class

Output :

B) Write [Link] 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 [Link] 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 [Link]

Dim str, rev As String

str = [Link]

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

[Link]("String is Palindrome : " & str)

Else

[Link]("String is Not Palindrome : " & str)

End If

End Sub

End Class

Output :

B) "How is the book [Link] 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 [Link] program to generate Sample Tree View control.

Answer :

Public Class Form1

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link]("Master")

[Link](0).[Link]("Student Details")

[Link](0).[Link]("Teacher Details")
[Link]("Examination")

[Link](1).[Link]("Internal Exam")

[Link](1).[Link]("External Exam")

[Link](1).[Link]("Practical Exam")

End Sub

End Class

Output :

B) Write a Web application in [Link] 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 [Link] 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 [Link]

Dim str As String

str = [Link]

Dim I, Count As Integer

Dim arr() As Char = [Link]

For I = 0 To [Link] - 1

If arr(I) = " " Then

Count = Count + 1

End If

Next

MsgBox(Count + 1 & " words")

End Sub

End Class

Output :

B) Write [Link] 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 [Link] 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 [Link]

[Link] = [Link]

End Sub

Private Sub GreenToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = [Link]

End Sub

Private Sub BlueToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles [Link]
[Link] = [Link]

End Sub

Private Sub MaximizeToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = [Link]

End Sub

Private Sub MiniMToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = [Link]

End Sub

Private Sub RestoreToolStripMenuItem_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = [Link]

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([Link]);

[Link](b);

[Link](c);

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

d = b + c;

[Link](d);

b = c;

c = d;

Output :
B) Create the application in [Link] 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)

[Link](prime(Convert.ToInt32([Link])));

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

records (Max 5). Delete a record of author who has written “[Link] book” and

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

Answer :

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\[Link]")

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

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

[Link](ds, "Author")

[Link] = ds

[Link] = "Author"
Return ds

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into Author values(" & [Link] & ",'" &
[Link] & "','" & [Link] & "')"

[Link]()

If [Link]() Then

[Link]("Inserted Successfully...!")

End If

[Link]()

[Link]()

display()

End Sub

Private Sub Button2_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "DELETE FROM Author WHERE book_name='" & [Link]


& "'"

[Link]()

If [Link]() Then
[Link]("Deleted Successfully...!")

End If

[Link]()

[Link]()

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 [Link] 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 [Link] 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 = [Link];

[Link]("Length : " + a);

Output :
B) Create a web application in [Link] 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)

[Link]([Link]);

private void button2_Click(object sender, EventArgs e)

[Link]();

for (int i = [Link]-1; i >= 0; i--)

[Link] ([Link][i]);

Output :
B) Write a [Link] 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 = [Link]();

[Link]("Individual characters from the string: ");

foreach (char c in characters) {

[Link](c + " ");

[Link]();

Output :

B) Write a [Link] 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 [Link]

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
[Link]

' Get the customer details from textboxes

Dim cname As String = [Link]()

Dim contactNo As String = [Link]()

Dim email As String = [Link]()

' Validate the inputs

If cname = "" Then

[Link]("Please enter customer name.", "Error",


[Link], [Link])

Return

End If

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

[Link]("Please enter valid contact number.",


"Error", [Link], [Link])

Return

End If

If email = "" Or Not [Link]("@") Then

[Link]("Please enter valid email address.", "Error",


[Link], [Link])

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)

[Link]("@CName", cname)

[Link]("@ContactNo", contactNo)

[Link]("@Email", email)

[Link]()

Dim rowsAffected As Integer = [Link]()

[Link]()

If rowsAffected > 0 Then

[Link]("Customer details saved


successfully.", "Success", [Link], [Link]
on)

Else

[Link]("Failed to save customer


details.", "Error", [Link], [Link])

End If

End Using

End Sub

End Class

Output :
SLIP NO 30

A) Write a [Link] 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 [Link]

[Link] = (Int([Link]) + Int([Link]) + Int([Link])


+ Int([Link]) + Int([Link]) + Int([Link]) +
Int([Link]))

[Link] = Int([Link]) + Int([Link]) + Int([Link])

[Link] = [Link] - [Link]

[Link]("Employee Name : " & [Link] & [Link]


& "Total Salary is : " & [Link])

End Sub

Private Sub TextBox2_Leave(sender As Object,


e As EventArgs) Handles [Link]

[Link] = ([Link] * 31) / 100

[Link] = ([Link] * 9) / 100

End Sub

End Class

Output :
B) Write a [Link] program to accept the details Supplier (SupId, SupName, Phone

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

Answer :

Imports [Link]

Public Class Form1

Dim con As New OleDbConnection("Provider=[Link].12.0;Data


Source=C:\Users\Saurabh\Desktop\New folder\[Link]")

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

Dim cmd As New OleDbCommand

Dim ds As New DataSet

Public Function display()

[Link](ds, "Supplier")

[Link] = ds

[Link] = "Supplier"

Return ds
End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

display()

End Sub

Private Sub Button1_Click(sender As Object,


e As EventArgs) Handles [Link]

[Link] = con

[Link] = [Link]

[Link] = "insert into Supplier values(" & [Link] & ",'" &
[Link] & "'," & [Link] & ",'" & [Link] & "')"

[Link]()

If [Link]() Then

[Link]("Inserted Successfully...!")

End If

[Link]()

[Link]()

display()

End Sub

End Class

Output :

Common questions

Powered by AI

When designing an ASP.Net program to handle dynamic elements such as color changes or validation messages, several considerations should be made to ensure usability and performance. First, client-side scripting (such as JavaScript or jQuery) should be utilized for instant feedback and to reduce server load. Responsive design is important to accommodate various device screens. Additionally, the program should ensure accessibility standards are met, such as providing alternative text for visually impaired users. Performance optimization is key, using techniques like CSS animations for smooth transitions and validating inputs client-side before involving server resources to improve efficiency .

The use of GridView control in ASP.Net applications significantly enhances data presentation by providing a structured and flexible way to display data in a tabular format. It supports features such as automatic sorting, paging, and updating of data, which makes it suitable for applications requiring dynamic data interactions. GridView can bind to various data sources like databases, providing real-time interaction with data. Its customizable templating and styling options enable developers to tailor the visual presentation and functionality to meet specific application requirements .

Using a Timer control in VB.NET programs enhances functionality by automating the regular update or refresh process at specified intervals, without needing manual user input each time. This is particularly useful for time-sensitive applications, such as updating real-time data (e.g., showing the current second continuously in a TextBox). It creates a more responsive and interactive interface by reducing the need for user intervention, thus ensuring consistent execution of tasks at precise intervals .

Direct database manipulation in VB.NET programs can lead to several security vulnerabilities. One primary concern is SQL Injection, where malicious users can inject and execute arbitrary SQL code by manipulating inputs. This happens because of the concatenation of SQL statements directly with input values without proper validation or parameterization. Another concern is the lack of access control, where unauthorized users could gain the ability to alter or delete records. Implementing command parameterization and validating user inputs are essential methods to mitigate these risks .

Type conversion in C#.Net applications is crucial when handling primitive data types, as it allows for seamless data manipulation and interfacing with different types. Converting an integer to a string can facilitate displaying numerical data in user interfaces, or preparing data for storage in text-based formats. Conversely, converting a string to an integer enables numerical operations to be performed on the data. Such conversions are performed using methods like Convert.ToInt32() or ToString(), ensuring the flexibility and functionality of software applications by allowing different data types to interact efficiently .

In C#.Net, a recursive function allows a function to call itself in order to divide a problem into sub-problems. For finding the factorial of a number, the recursive approach works by breaking down the problem into smaller instances of itself, where the factorial of a number 'n' is defined as 'n' multiplied by the factorial of 'n-1', until the base case of factorial(1) is reached. This self-calling mechanism simplifies complex operations such as calculating factorials by utilizing a straightforward divide-and-conquer strategy .

Failing to handle exceptions properly in an ASP.Net application that checks for palindrome numbers can have several negative ramifications. It can lead to unexpected application crashes or unhandled errors, which degrade the user experience by providing little feedback on what went wrong. This lack of clear error messages can confuse users and complicate troubleshooting efforts. Proper exception handling involves capturing exceptions through try-catch blocks and logging detailed error information to assist with debugging while providing user-friendly messages that guide corrective actions .

Inheritance in C#.Net helps streamline code by enabling a class (termed as a derived class) to inherit fields, methods, and properties from another class (termed as a base class). This allows for code reuse, where common functionalities are defined in the base class, thereby reducing redundancy when implementing related classes. For instance, when creating base and derived classes for departments, inheritance allows each derived class (like Sales and Human Resources) to automatically possess core attributes defined in the base Department class, while also allowing each to extend functionality with additional unique attributes or methods. This results in cleaner, more modular code that's easier to maintain and extend .

A C#.Net application can efficiently manage memory when dealing with large datasets by employing several strategies. First, it should utilize arrays or collections with dynamic sizing, such as List<T> for ease of resizing and memory management. Additionally, implementing garbage collection effectively by disposing of unused objects promptly using the 'using' statement or calling the Dispose method can help. Using asynchronous programming models helps in managing resource allocation better for operations such as reading and reversing large data sets. Moreover, efficient algorithms should be employed to minimize the computational load and memory footprint during operations like reversing the dataset .

Encapsulation enhances code maintainability and readability in a C#.Net program by bundling data with the code that manipulates it, thus hiding the complex implementation details from the user. This allows individual components to be modified without affecting other parts of the program, leading to easier maintenance and reduced risk of bugs when changes are made. Encapsulation also improves readability by organizing code into distinct sections with clear interfaces, making it easier to understand the flow and logic of operations such as addition and multiplication in a complex program .

You might also like