Dot Net Practical Solved Slips
Dot Net Practical Solved Slips
[Link]
using System;
using [Link];
using [Link];
using [Link];
namespace DepartmentApp
{
public partial class Default : [Link]
{
string conString = "Server=localhost;Database=CompanyDB;Uid=root;Pwd=root;";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
protected void btnInsert_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(conString))
{
string query = "INSERT INTO Department (DeptId, DeptName, EmpName, Salary)
VALUES (@DeptId, @DeptName, @EmpName, @Salary)";
using (MySqlCommand cmd = new MySqlCommand(query, con))
{
[Link]("@DeptId", Convert.ToInt32([Link]));
[Link]("@DeptName", [Link]);
[Link]("@EmpName", [Link]);
[Link]("@Salary", [Link]([Link]));
[Link]();
[Link]();
[Link]();
}
}
LoadData();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(conString))
{
[Link]();
string getSalaryQuery = "SELECT Salary FROM Department WHERE EmpName =
@EmpName";
decimal currentSalary = 0;
using (MySqlCommand cmd = new MySqlCommand(getSalaryQuery, con))
{
[Link]("@EmpName", [Link]);
object result = [Link]();
if (result != null)
{
currentSalary = [Link](result);
}
}
decimal newSalary = currentSalary * 1.15m;
string updateQuery = "UPDATE Department SET Salary = @NewSalary WHERE
EmpName = @EmpName";
using (MySqlCommand cmd = new MySqlCommand(updateQuery, con))
{
[Link]("@NewSalary", newSalary);
[Link]("@EmpName", [Link]);
[Link]();
}
}
LoadData();
}
protected void btnDelete_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(conString))
{
string query = "DELETE FROM Department WHERE EmpName = @EmpName";
[Link] = dt;
[Link]();
}
}
}
}
}
Output:-
B) Design a [Link] form to pick a date from DateTimePicker Control and display day,
month and year in separate text boxes.
Code:-
using System;
using [Link];
namespace DatePickerApp
{
public partial class nice : Form
{
public nice()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DateTime selectedDate = [Link];
[Link] = [Link]();
[Link] = [Link]();
[Link] = [Link]();
}
}
}
Output:-
SLIP-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.
Code:-
Module Module1
Sub Main()
' Prompt the user to enter a character
[Link]("Please enter a character: ")
Dim input As String = [Link]()
' Check if the input is a single character
If [Link] <> 1 Then
[Link]("Please enter only one character.")
Return
End If
Dim character As Char = [Link](input(0)) ' Convert to lowercase for easier
comparison
' Check if the character is a letter
If Not [Link](character) Then
[Link]("The input is not a valid letter.")
Return
End If
' Determine if the character is a vowel or consonant
Dim isVowel As Boolean = "aeiou".Contains(character)
' Display the result
If isVowel Then
[Link]("The character '{0}' is a vowel.", input(0))
Else
[Link]("The character '{0}' is a consonant.", input(0))
End If
' Display the case of the character
If [Link](input(0)) Then
[Link]("The character is uppercase.")
Else
[Link]("The character is lowercase.")
End If
' Wait for user input before closing
[Link]("Press any key to exit...")
[Link]()
End Sub
End Module
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.
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="[Link]"
Inherits="Default" %>
<!DOCTYPE html>
<html>
<head>
<title>Loan Calculator</title>
</head>
<body>
<form id="form1" runat="server">
<div style="margin: 20px; font-family: Arial; max-width: 400px;">
<h2>Loan Calculator</h2>
<div style="margin-bottom: 10px;">
<label for="txtLoanAmount">Loan Amount:</label><br />
<asp:TextBox ID="txtLoanAmount" runat="server" Width="200px"></asp:TextBox>
</div>
<div style="margin-bottom: 10px;">
<label for="txtInterestRate">Interest Rate (%):</label><br />
<asp:TextBox ID="txtInterestRate" runat="server" Width="200px"></asp:TextBox>
</div>
<div style="margin-bottom: 10px;">
<label for="txtDuration">Duration (Years):</label><br />
<asp:TextBox ID="txtDuration" runat="server" Width="200px"></asp:TextBox>
</div>
<div style="margin-bottom: 10px;">
<asp:Button ID="btnCalculate" runat="server" Text="Calculate Interest"
OnClick="btnCalculate_Click" />
</div>
<div style="margin-top: 10px;">
<asp:Label ID="lblResult" runat="server" Text="" ForeColor="Blue"></asp:Label>
</div>
</div>
</form>
</body>
</html>
[Link]
using System;
public partial class Default : [Link]
{
protected void btnCalculate_Click(object sender, EventArgs e)
{
try
{
double loanAmount = [Link]([Link]);
double interestRate = [Link]([Link]);
int duration = [Link]([Link]);
double simpleInterest = (loanAmount * interestRate * duration) / 100;
[Link] = $"The calculated Simple Interest is: {simpleInterest:C}";
}
catch (FormatException)
{
[Link] = "Please enter valid numeric values.";
} catch (Exception ex)
{
[Link] = $"An error occurred: {[Link]}";
}
}
}
Output:-
SLIP-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.
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="[Link]"
Inherits="Default" %>
<!DOCTYPE html>
<html>
<head>
<title>Flower Selection</title>
</head>
<body>
<form id="form1" runat="server">
<div style="margin: 20px; font-family: Arial;">
<h2>Select Your Favorite Flower</h2>
<!-- RadioButtonList to display flowers in two columns -->
<asp:RadioButtonList
ID="rblFlowers"
runat="server"
RepeatColumns="2"
RepeatDirection="Horizontal"
Font-Size="Medium">
<asp:ListItem>Rose</asp:ListItem>
<asp:ListItem>Lily</asp:ListItem>
<asp:ListItem>Tulip</asp:ListItem>
<asp:ListItem>Daisy</asp:ListItem>
<asp:ListItem>Orchid</asp:ListItem>
<asp:ListItem>Sunflower</asp:ListItem>
</asp:RadioButtonList>
<br />
<!-- Button to display the selected flower -->
<asp:Button
ID="btnSubmit"
runat="server"
Text="Show Selected Flower"
OnClick="btnSubmit_Click" />
<br /><br />
<!-- Label to display the selected flower -->
<asp:Label
ID="lblSelectedFlower"
runat="server"
Text=""
Font-Bold="True"
ForeColor="Green"
Font-Size="Large">
</asp:Label>
</div>
</form>
</body>
</html>
[Link]
using System;
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if ([Link] != null)
{
[Link] = $"You selected: {[Link]}";
}
else
{
[Link] = "Please select a flower.";
}
}
}
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.
Code:-
Imports [Link]
Imports [Link]
Imports [Link]
Public Class Form1
Dim conString As String = "Server=localhost;Database=emp;User ID=root;Pwd=root;"
Dim con As New MySqlConnection(conString)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
CreateMovieTable()
LoadMovies()
End Sub
Private Sub CreateMovieTable()
Dim query As String = "CREATE TABLE IF NOT EXISTS Movie (Mv_Name VARCHAR(255),
Release_Year INT, Director VARCHAR(255));"
ExecuteQuery(query)
End Sub
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles [Link]
If [Link] = "" Or [Link] = "" Or [Link] = "" Then
[Link]("Please fill all fields!", "Error", [Link],
[Link])
Return
End If
Dim query As String = "INSERT INTO Movie (Mv_Name, Release_Year, Director) VALUES
(@MvName, @ReleaseYear, @Director);"
ExecuteQuery(query, New MySqlParameter("@MvName", [Link]),
New MySqlParameter("@ReleaseYear", Convert.ToInt32([Link])),
New MySqlParameter("@Director", [Link]))
[Link]("Movie Inserted!", "Success", [Link],
[Link])
LoadMovies()
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles [Link]
Dim query As String = "DELETE FROM Movie WHERE Release_Year = 2022;"
ExecuteQuery(query)
[Link]("Movies released in 2022 have been deleted!", "Deleted",
[Link], [Link])
LoadMovies()
End Sub
Private Sub LoadMovies()
Dim query As String = "SELECT * FROM Movie;"
Dim adapter As New MySqlDataAdapter(query, con)
Dim dt As New DataTable()
[Link](dt)
[Link] = dt
End Sub
Private Sub ExecuteQuery(query As String, ParamArray parameters() As MySqlParameter)
Try
[Link]()
Dim cmd As New MySqlCommand(query, con)
[Link](parameters)
[Link]()
Catch ex As Exception
[Link]([Link], "Database Error", [Link],
[Link])
Finally
[Link]()
End Try
End Sub
End Class
Output:-
SLIP-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.
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Perfect Number Validator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Check if a Number is Perfect</h2>
<!-- TextBox for number input -->
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
<!-- Button to trigger validation -->
<asp:Button ID="btnCheck" runat="server" Text="Check" OnClick="btnCheck_Click"
/>
<!-- Label to display the result -->
<asp:Label ID="lblResult" runat="server" ForeColor="Red"></asp:Label>
</div>
</form>
</body>
</html>
[Link]
using System;
namespace YourNamespace
{
public partial class PerfectNumber : [Link]
{
private bool IsPerfectNumber(int number)
{
int sum = 0;
for (int i = 1; i < number; i++)
{
if (number % i == 0)
{
sum += i;
}
}
return sum == number;
}
protected void btnCheck_Click(object sender, EventArgs e)
{
try
{
int number = Convert.ToInt32([Link]());
if (!IsPerfectNumber(number))
{
throw new Exception("The number is not a perfect number.");
}
[Link] = [Link];
[Link] = "The number is a perfect number!";
}
catch (FormatException)
{
[Link] = [Link];
[Link] = "Please enter a valid number.";
}
catch (Exception ex)
{
[Link] = [Link];
} } } }
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.
Code:-
Imports [Link]
Imports [Link].Asn1
Imports [Link]
Imports [Link]
Public Class Form1
Dim conString As String = "Server=localhost;Database=emp;User ID=root;Pwd=root;"
Dim con As New MySqlConnection(conString)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
CreateStudentTable()
LoadStudents()
End Sub
Private Sub CreateStudentTable()
Dim query As String = "CREATE TABLE IF NOT EXISTS Student (RollNo INT PRIMARY KEY,
SName VARCHAR(255), Class VARCHAR(50), City VARCHAR(255));"
ExecuteQuery(query)
End Sub
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles [Link]
If [Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Then
[Link]("Please fill all fields!", "Error", [Link],
[Link])
Return
End If
Dim query As String = "INSERT INTO Student (RollNo, SName, Class, City) VALUES
(@RollNo, @SName, @Class, @City);"
ExecuteQuery(query, New MySqlParameter("@RollNo",
Convert.ToInt32([Link])),
New MySqlParameter("@SName", [Link]),
New MySqlParameter("@Class", [Link]),
New MySqlParameter("@City", [Link]))
[Link]("Student Inserted!", "Success", [Link],
[Link])
LoadStudents()
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles [Link]
Dim query As String = "UPDATE Student SET City = 'Pune' WHERE City = 'Mumbai';"
ExecuteQuery(query)
[Link]("Students from Mumbai have been updated to Pune!", "Updated",
[Link], [Link])
LoadStudents()
End Sub
Private Sub LoadStudents()
Dim query As String = "SELECT * FROM Student;"
Dim adapter As New MySqlDataAdapter(query, con)
Dim dt As New DataTable()
[Link](dt)
[Link] = dt
End Sub
Private Sub ExecuteQuery(query As String, ParamArray parameters() As MySqlParameter)
Try
[Link]()
Dim cmd As New MySqlCommand(query, con)
[Link](parameters)
[Link]()
Catch ex As Exception
[Link]([Link], "Database Error", [Link],
[Link])
Finally
[Link]()
End Try
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
[Link]
End Sub
End Class
Output:-
SLIP-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).
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Employee List</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBoxEmployees" runat="server" SelectionMode="Multiple"
Width="200px" Height="200px">
<asp:ListItem Text="Ashish Solanki" Value="Ashish Solanki"></asp:ListItem>
<asp:ListItem Text="Bhushan Gaikwad" Value="Bhushan
Gaikwad"></asp:ListItem>
<asp:ListItem Text="Ronit Shinde" Value="Ronit Shinde"></asp:ListItem>
<asp:ListItem Text="Animesh Kamble" Value="Animesh Kamble"></asp:ListItem>
<asp:ListItem Text="Arya Shinde" Value="Arya Shinde"></asp:ListItem>
</asp:ListBox>
<br />
<asp:Button ID="ButtonAdd" runat="server" Text="Add Selected"
OnClick="ButtonAdd_Click" />
<br />
<asp:TextBox ID="TextBoxOutput" runat="server" TextMode="MultiLine" Rows="10"
Columns="30"></asp:TextBox>
</div>
</form>
</body>
</html>
[Link]
using System;
using [Link];
using [Link];
namespace YourNamespace
{
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonAdd_Click(object sender, EventArgs e)
{
StringBuilder selectedEmployees = new StringBuilder();
foreach (ListItem item in [Link])
{
if ([Link])
{
[Link]([Link]);
}
}
if ([Link] == 0)
{
foreach (ListItem item in [Link])
{
[Link]([Link]);
}
}
[Link] = [Link]();
}
}
}
Output:-
B) Write a c#.Net program for multiplication of matrices.
Code:-
using System;
namespace MatrixMultiplication
{
class Program
{
static void Main(string[] args)
{
[Link]("Enter the number of rows for the first matrix:");
int rowsA = [Link]([Link]());
[Link]("Enter the number of columns for the first matrix:");
int colsA = [Link]([Link]());
[Link]("Enter the number of rows for the second matrix:");
int rowsB = [Link]([Link]());
[Link]("Enter the number of columns for the second matrix:");
int colsB = [Link]([Link]());
if (colsA != rowsB)
{
[Link]("Matrix multiplication is not possible. The number of columns in
the first matrix must equal the number of rows in the second matrix.");
return;
}
int[,] matrixA = new int[rowsA, colsA];
int[,] matrixB = new int[rowsB, colsB];
int[,] resultMatrix = new int[rowsA, colsB];
[Link]("Enter elements for the first matrix:");
for (int i = 0; i < rowsA; i++)
{
for (int j = 0; j < colsA; j++)
{
[Link]($"Element [{i + 1},{j + 1}]: ");
matrixA[i, j] = [Link]([Link]());
}
}
[Link]("Enter elements for the second matrix:");
for (int i = 0; i < rowsB; i++)
{
for (int j = 0; j < colsB; j++)
{
[Link]($"Element [{i + 1},{j + 1}]: ");
matrixB[i, j] = [Link]([Link]());
}
}
for (int i = 0; i < rowsA; i++)
{
for (int j = 0; j < colsB; j++)
{
for (int k = 0; k < colsA; k++)
{
resultMatrix[i, j] += matrixA[i, k] * matrixB[k, j];
}
}
}
[Link]("Resultant Matrix:");
for (int i = 0; i < rowsA; i++)
{
for (int j = 0; j < colsB; j++)
{
[Link](resultMatrix[i, j] + "\t");
}
[Link]();
}
}
}
}
Output:-
SLIP-9
A) Write a Menu driven program in C#.Net to perform following functionality: Addition,
Multiplication, Subtraction, Division.
Code:-
using System;
namespace MenuDrivenCalculator
{
class Program
{
static void Main(string[] args)
{
int choice;
do
{
[Link]("Menu:");
[Link]("1. Addition");
[Link]("2. Subtraction");
[Link]("3. Multiplication");
[Link]("4. Division");
[Link]("5. Exit");
[Link]("Enter your choice (1-5): ");
choice = [Link]([Link]());
switch (choice)
{
case 1:
PerformAddition();
break;
case 2:
PerformSubtraction();
break;
case 3:
PerformMultiplication();
break;
case 4:
PerformDivision();
break;
case 5:
[Link]("Exiting the program.");
break;
default:
[Link]("Invalid choice. Please select a valid option.");
break;
}
[Link](); // Blank line for better readability
} while (choice != 5);
}
static void PerformAddition()
{
[Link]("Enter first number: ");
double num1 = [Link]([Link]());
[Link]("Enter second number: ");
double num2 = [Link]([Link]());
double result = num1 + num2;
[Link]($"Result: {num1} + {num2} = {result}");
}
static void PerformSubtraction()
{
[Link]("Enter first number: ");
double num1 = [Link]([Link]());
[Link]("Enter second number: ");
double num2 = [Link]([Link]());
double result = num1 - num2;
[Link]($"Result: {num1} - {num2} = {result}");
}
static void PerformMultiplication()
{
[Link]("Enter first number: ");
double num1 = [Link]([Link]());
[Link]("Enter second number: ");
double num2 = [Link]([Link]());
double result = num1 * num2;
[Link]($"Result: {num1} * {num2} = {result}");
}
static void PerformDivision()
{
[Link]("Enter first number: ");
double num1 = [Link]([Link]());
[Link]("Enter second number: ");
double num2 = [Link]([Link]());
if (num2 == 0)
{
[Link]("Error: Division by zero is not allowed.");
}
else
{
double result = num1 / num2;
[Link]($"Result: {num1} / {num2} = {result}");
} } } }
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".
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>Palindrome Checker</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Palindrome Checker</h2>
<asp:Label ID="lblEnterNumber" runat="server" Text="Enter a
number:"></asp:Label>
<asp:TextBox ID="getnum" runat="server"></asp:TextBox>
<asp:Button ID="btnCheck" runat="server" Text="Check" OnClick="btnCheck_Click"
/>
<br /><br />
<asp:Label ID="lbldisplay" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
[Link]
using System;
namespace YourNamespace
{
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCheck_Click(object sender, EventArgs e)
{
string inputNumber = [Link];
if (IsPalindrome(inputNumber))
{
[Link] = $"{inputNumber} is a palindrome.";
}
else
{
[Link] = $"{inputNumber} is not a palindrome.";
}
}
private bool IsPalindrome(string number)
{
string cleanedNumber = [Link]();
char[] charArray = [Link]();
[Link](charArray);
string reversedNumber = new string(charArray);
return [Link](reversedNumber,
[Link]);
}
}
}
Output:-
SLIP-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.
Code:-
using System;
namespace PrimitiveDataTypesDemo
{
class Program
{
static void Main(string[] args)
{
int integerValue = 42;
double doubleValue = 3.14;
char charValue = 'A';
bool boolValue = true;
string stringValue = "Hello, Ashish!";
[Link]("Primitive Data Types:");
[Link]($"Integer: {integerValue}");
[Link]($"Double: {doubleValue}");
[Link]($"Character: {charValue}");
[Link]($"Boolean: {boolValue}");
[Link]($"String: {stringValue}");
[Link]();
string convertedString = [Link]();
[Link]($"Converted Integer to String: {convertedString}");
[Link]($"Type of converted value: {[Link]()}");
[Link]();
[Link]("Enter a number to convert to Integer: ");
string userInput = [Link]();
if ([Link](userInput, out int convertedInteger))
{
[Link]($"Converted String to Integer: {convertedInteger}");
[Link]($"Type of converted value: {[Link]()}");
}
else
{
[Link]("Invalid input! Please enter a valid integer.");
}
[Link]("\nPress any key to exit...");
[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 .
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>MySQL Connection Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>MySQL Connection Test</h2>
<asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
[Link]
using System;
using [Link];
namespace YourNamespace
{
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string connectionString =
"Server=localhost;Database=StudentDB;UserID=root;Password=root;";
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
try
{
[Link]();
[Link] = "Connection has been established.";
}
catch (Exception ex)
{
[Link] = "Error: " + [Link];
}
}
}
}
}
}
Output:-
SLIP-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.
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Payment Form</title>
<style>
.error { color: red; }
</style>
</head>
<body>
<form id="form1" runat="server">
<h2>Payment Form</h2>
<div>
<label for="txtName">User Name:</label>
<asp:TextBox ID="txtName" runat="server" />
<asp:Label ID="nameError" runat="server" CssClass="error" />
</div>
<div>
<label for="ddlPaymentMode">Mode of Payment:</label>
<asp:DropDownList ID="ddlPaymentMode" runat="server">
<asp:ListItem Value="CreditCard">Credit Card</asp:ListItem>
<asp:ListItem Value="PayPal">PayPal</asp:ListItem>
<asp:ListItem Value="BankTransfer">Bank Transfer</asp:ListItem>
</asp:DropDownList>
</div>
<div>
<label for="txtCardNumber">Credit Card Number:</label>
<asp:TextBox ID="txtCardNumber" runat="server" />
<asp:Label ID="cardError" runat="server" CssClass="error" />
</div>
<div>
<asp:Button ID="btnValidate" Text="Validate" OnClick="btnValidate_Click"
runat="server" />
</div>
<div>
<asp:Label ID="validationMessage" runat="server" CssClass="error" />
</div>
</form>
</body>
</html>
[Link]
using System;
using [Link];
namespace WebApplication
{
public partial class PaymentForm : Page
{
protected void btnValidate_Click(object sender, EventArgs e)
{
bool isValid = true;
[Link] = "";
[Link] = "";
[Link] = "";
if ([Link]([Link]))
{
[Link] = "User Name is required.";
isValid = false;
}
if ([Link] == "CreditCard")
{
if ([Link]([Link]) || [Link] !=
16)
{
[Link] = "Credit Card Number must be 16 digits.";
isValid = false;
}
else
{ if ()
{
[Link] = "Credit Card Number must be numeric.";
isValid = false;
}
}
}
if (isValid)
{
[Link] = "All inputs are valid!";
[Link] = [Link];
}
else
{
[Link] = "Please correct the errors.";
[Link] = [Link];
}
}
}
}
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.
Code:-
using System;
namespace FruitBasket {
public class Fruit
{
protected int totalFruits;
public Fruit()
{
totalFruits = 0;
}
public void AddFruits(int count)
{
totalFruits += count;
}
.green-button:hover {
background-color: yellow;
color: black; /* Optional: Change text color on hover */
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnColorChange" runat="server" Text="Hover Over Me!"
CssClass="green-button" />
</div>
</form>
</body>
</html>
[Link]
using System;
namespace YourNamespace
{
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
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.
Code:-
Imports [Link]
Public Class Form1
' Connection string to your MySQL database
Dim connectionString As String = "Server=localhost;Database=StudentDB;User
ID=root;Password=root;"
' Method to create the Player table (if it doesn't exist)
Private Sub CreateTable()
Using connection As New MySqlConnection(connectionString)
[Link]()
' SQL query to create the Player table
Dim createTableQuery As String = "
CREATE TABLE IF NOT EXISTS Player (
PID INT PRIMARY KEY,
PName VARCHAR(100),
Game VARCHAR(50),
no_of_matches INT
);"
Dim cmd As New MySqlCommand(createTableQuery, connection)
[Link]()
End Using
End Sub
' Method to insert some initial records
Private Sub InsertRecords()
Using connection As New MySqlConnection(connectionString)
[Link]()
Dim insertQuery As String = "INSERT INTO Player (PID, PName, Game,
no_of_matches) VALUES
(4, 'Malinga', 'Cricket', 30),
(5, 'Gail', 'Cricket', 40),
(6, 'SAchin', 'Cricket', 300);"
Dim cmd As New MySqlCommand(insertQuery, connection)
[Link]()
End Using
End Sub
' Method to update the number of matches for 'Rohit Sharma'
Private Sub UpdateMatches()
Using connection As New MySqlConnection(connectionString)
[Link]()
Dim updateQuery As String = "UPDATE Player SET no_of_matches = 55 WHERE
PName = 'Rohit Sharma';"
Dim cmd As New MySqlCommand(updateQuery, connection)
[Link]()
End Using
End Sub
' Method to load the data into DataGridView
Private Sub LoadData()
Using connection As New MySqlConnection(connectionString)
[Link]()
Dim selectQuery As String = "SELECT * FROM Player;"
Dim cmd As New MySqlCommand(selectQuery, connection)
Dim adapter As New MySqlDataAdapter(cmd)
Dim dt As New DataTable()
[Link](dt)
' Binding data to DataGridView
[Link] = dt
End Using
End Sub
' Event handler for the button click to update matches and refresh DataGridView
Private Sub btnUpdate_Click(sender As Object, e As EventArgs)
UpdateMatches() ' Update the number of matches for 'Rohit Sharma'
LoadData() ' Refresh DataGridView with updated data
End Sub
' Form Load event to setup initial conditions
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
CreateTable() ' Ensure the table exists
InsertRecords() ' Insert initial data
LoadData() ' Load data into DataGridView
End Sub
Private Sub btnUpdate_Click_1(sender As Object, e As EventArgs) Handles
[Link]
End Sub
End Class
Output:-
SLIP-13
A) Write a [Link] program for blinking an image.
Code:-
Public Class Form1
Private imageVisible As Boolean = True
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles [Link]
If imageVisible Then
[Link] = False
Else
[Link] = True
End If
imageVisible = Not imageVisible
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
' Set the timer interval (500 ms)
[Link] = 500
[Link]() ' Start the timer
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.
Code:-
using System;
class Student
{
public int RollNo;
public string Name;
public double Marks1, Marks2, Marks3;
public double Percentage;
public void AcceptDetails()
{
[Link]("Enter Roll No:");
RollNo = Convert.ToInt32([Link]());
[Link]("Enter Name:");
Name = [Link]();
[Link]("Enter Marks in Subject 1:");
Marks1 = [Link]([Link]());
[Link]("Enter Marks in Subject 2:");
Marks2 = [Link]([Link]());
[Link]("Enter Marks in Subject 3:");
Marks3 = [Link]([Link]());
CalculatePercentage();
}
public void CalculatePercentage()
{
double totalMarks = Marks1 + Marks2 + Marks3;
Percentage = (totalMarks / 300) * 100; // Assuming each subject is out of 100
}
public void DisplayDetails()
{
[Link]("\nStudent Details:");
[Link]("Roll No: " + RollNo);
[Link]("Name: " + Name);
[Link]("Marks in Subject 1: " + Marks1);
[Link]("Marks in Subject 2: " + Marks2);
[Link]("Marks in Subject 3: " + Marks3);
[Link]("Percentage: " + Percentage + "%\n");
}
}
class Program
{
static void Main(string[] args)
{
[Link]("Enter number of students:");
int n = Convert.ToInt32([Link]());
Student[] students = new Student[n];
for (int i = 0; i < n; i++)
{
[Link]($"\nEnter details for student {i + 1}:");
students[i] = new Student(); // Create a new student object
students[i].AcceptDetails(); // Accept student details
}
for (int i = 0; i < n; i++)
{
students[i].DisplayDetails(); // Display student details
}
}
}
Output:-
SLIP-14
A) Write a program in C#.Net to find the sum of all elements of the array.
Code:-
using System;
class Program
{
static void Main(string[] args)
{
int[] numbers = { 10, 20, 30, 40, 50 };
int sum = 0;
for (int i = 0; i < [Link]; i++)
{
sum += numbers[i];
}
[Link]("The sum of all elements in the array is: " + sum);
}
}
Output:-
B) Write a C#.Net Program to define a class Person having members –name, address.
Create a subclass called employee with member staffed, salary. Create ‘n’ objects of
the Employee class and display all the details of the Employee.
Code:-
using System;
class Person
{
public string Name;
public string Address;
public Person(string name, string address)
{
Name = name;
Address = address;
}
public void DisplayPersonDetails()
{
[Link]($"Name: {Name}");
[Link]($"Address: {Address}");
}
}
class Employee : Person
{
public string Staffed;
public double Salary;
public Employee(string name, string address, string staffed, double salary)
: base(name, address)
{
Staffed = staffed;
Salary = salary;
}
public void DisplayEmployeeDetails()
{
DisplayPersonDetails();
[Link]($"Staffed: {Staffed}");
[Link]($"Salary: {Salary}");
[Link]();
}
}
class Program
{
static void Main(string[] args)
{
[Link]("Enter the number of employees: ");
int n = Convert.ToInt32([Link]());
Employee[] employees = new Employee[n];
for (int i = 0; i < n; i++)
{
[Link]($"\nEnter details for employee {i + 1}:");
[Link]("Enter Name: ");
string name = [Link]();
[Link]("Enter Address: ");
string address = [Link]();
[Link]("Enter Staffed Position: ");
string staffed = [Link]();
[Link]("Enter Salary: ");
double salary = [Link]([Link]());
employees[i] = new Employee(name, address, staffed, salary);
}
[Link]("\nEmployee Details:\n");
for (int i = 0; i < n; i++)
{
employees[i].DisplayEmployeeDetails();
}
}
}
Output:-
SLIP-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.
Code:-
[Link]
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="[Link]" Inherits="[Link]" %>
<asp:DropDownList ID="ddlColors" runat="server">
<asp:ListItem Text="Red" Value="Red" />
<asp:ListItem Text="Green" Value="Green" />
<asp:ListItem Text="Blue" Value="Blue" />
<asp:ListItem Text="Yellow" Value="Yellow" />
<asp:ListItem Text="Pink" Value="Pink" />
<asp:ListItem Text="Purple" Value="Purple" />
<asp:ListItem Text="Orange" Value="Orange" />
<asp:ListItem Text="Black" Value="Black" />
</asp:DropDownList>
<asp:Button ID="btnChangeColor" runat="server" Text="Change Color"
OnClick="btnChangeColor_Click" />
[Link]
using System;
using [Link];
namespace YourNamespace
{
public partial class ColorSelector : UserControl
{
protected void btnChangeColor_Click(object sender, EventArgs e)
{
ColorChanged?.Invoke(this, new
ColorChangedEventArgs([Link]));
}
public event EventHandler<ColorChangedEventArgs> ColorChanged;
}
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<%@ Register Src="~/[Link]" TagPrefix="uc" TagName="ColorSelector" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Color Selector Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Select a Color to Change Background</h2>
<uc:ColorSelector ID="ColorSelector1" runat="server"
OnColorChanged="ColorSelector1_ColorChanged" />
</div>
</form>
</body>
</html>
[Link]
using System;
using [Link];
namespace YourNamespace
{
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ColorSelector1_ColorChanged(object sender, ColorChangedEventArgs
e)
{
string script = $"[Link] = '{[Link]}';";
[Link]([Link](), "ChangeBackgroundColor", script,
true);
}
}
}
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
Code:-
using System;
class Customer
{
public int CustomerNo;
public string Name;
public string Address;
public int ItemNo;
public int Quantity;
public double Price;
public Customer(int customerNo, string name, string address, int itemNo, int quantity,
double price)
{
CustomerNo = customerNo;
Name = name;
Address = address;
ItemNo = itemNo;
Quantity = quantity;
Price = price;
}
public double CalculateTotalPrice()
{
return Quantity * Price;
}
public void DisplayCustomerDetails()
{
[Link]("\nCustomer Details:");
[Link]($"Customer No: {CustomerNo}");
[Link]($"Name: {Name}");
[Link]($"Address: {Address}");
[Link]($"Item No: {ItemNo}");
[Link]($"Quantity: {Quantity}");
[Link]($"Price per item: {Price}");
[Link]($"Total Price: {CalculateTotalPrice():C}");
}
}
class Program
{
static void Main(string[] args)
{
[Link]("Enter the number of customers: ");
int n = Convert.ToInt32([Link]());
Customer[] customers = new Customer[n];
for (int i = 0; i < n; i++)
{
[Link]($"\nEnter details for customer {i + 1}:");
[Link]("Enter Customer No: ");
int customerNo = Convert.ToInt32([Link]());
[Link]("Enter Name: ");
string name = [Link]();
[Link]("Enter Address: ");
string address = [Link]();
[Link]("Enter Item No: ");
int itemNo = Convert.ToInt32([Link]());
[Link]("Enter Quantity: ");
int quantity = Convert.ToInt32([Link]());
[Link]("Enter Price per item: ");
double price = [Link]([Link]());
customers[i] = new Customer(customerNo, name, address, itemNo, quantity, price);
}
double grandTotal = 0;
[Link]("\nCustomer Details and Total Prices:\n");
for (int i = 0; i < n; i++)
{
customers[i].DisplayCustomerDetails();
grandTotal += customers[i].CalculateTotalPrice();
}
[Link]($"\nGrand Total of all items: {grandTotal:C}");
}
}
Output:-
SLIP-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.
Code:-
[Link]
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="[Link]" Inherits="[Link]" %>
<asp:TextBox ID="txtUsername" runat="server" placeholder="Username" />
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"
placeholder="Password" />
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
<asp:Label ID="lblMessage" runat="server" ForeColor="Red" />
[Link]
using System;
namespace YourNamespace
{
public partial class LoginControl : [Link]
{
protected void btnLogin_Click(object sender, EventArgs e)
{
if ([Link] == "DYP" && [Link] == "Pimpri")
{
[Link] = "Authorized";
[Link] = [Link];
}
else
{
[Link] = "Invalid username or password";
[Link] = [Link];
}
}
}
}
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<%@ Register Src="~/[Link]" TagPrefix="uc" TagName="LoginControl" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Login Example</title>
</head>
<body>
<form id="form1" runat="server">
<uc:LoginControl ID="LoginControl1" runat="server" />
</form>
</body>
</html>
[Link]
using System;
namespace YourNamespace
{
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
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.
Code:-
using System;
class Supplier
{
public int Sid;
public string Name;
public string Address;
public string Pincode;
}
class Program
{
static void Main()
{
int n;
[Link]("Enter number of suppliers: ");
n = [Link]([Link]());
Supplier[] suppliers = new Supplier[n];
for (int i = 0; i < n; i++)
{
suppliers[i] = new Supplier();
[Link]($"Enter details for Supplier {i + 1}:");
[Link]("Enter Supplier ID: ");
suppliers[i].Sid = [Link]([Link]());
[Link]("Enter Name: ");
suppliers[i].Name = [Link]();
[Link]("Enter Address: ");
suppliers[i].Address = [Link]();
[Link]("Enter Pincode: ");
suppliers[i].Pincode = [Link]();
}
[Link]("\nSupplier Details:");
for (int i = 0; i < n; i++)
{
[Link]($"Supplier ID: {suppliers[i].Sid}");
[Link]($"Name: {suppliers[i].Name}");
[Link]($"Address: {suppliers[i].Address}");
[Link]($"Pincode: {suppliers[i].Pincode}\n");
}
}
}
Output:-
SLIP-17
A) Write a C#.Net application to display the vowels from a given String.
Code:-
using System;
using [Link];
class Program
{
static void Main()
{
[Link]("Enter a string: ");
string input = [Link]();
string vowels = "aeiouAEIOU";
string result = "";
foreach (char c in input)
{
if ([Link](c))
{
result += c;
}
}
[Link]("Vowels in the string: " + result);
}
}
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.
Code:-
[Link]
<configuration>
<connectionStrings>
<add name="StudentDB"
connectionString="Server=localhost;Database=StudentDB;User
ID=root;Password=root;"/>
</connectionStrings>
</configuration>
[Link]
Imports [Link]
Imports [Link]
Public Class Form1
Private connectionString As String =
[Link]("StudentDB").ConnectionString
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles [Link]
Dim pid As Integer = [Link]([Link])
Dim pname As String = [Link]
Dim expiryDate As Date = [Link]([Link])
Dim price As Decimal = [Link]([Link])
Using connection As New MySqlConnection(connectionString)
Dim command As New MySqlCommand("INSERT INTO Products (PID, PName,
ExpiryDate, Price) VALUES (@PID, @PName, @ExpiryDate, @Price)", connection)
[Link]("@PID", pid)
[Link]("@PName", pname)
[Link]("@ExpiryDate", expiryDate)
[Link]("@Price", price)
[Link]()
[Link]()
[Link]()
End Using
LoadData()
End Sub
Private Sub LoadData()
Using connection As New MySqlConnection(connectionString)
Dim adapter As New MySqlDataAdapter("SELECT * FROM Products", connection)
Dim table As New DataTable()
[Link](table)
[Link] = table
End Using
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
LoadData()
End Sub
End Class
Output:-
SLIP-18
A) Write a [Link] program to accept a number from user through input box and
display its multiplication table into the list box.
Code:-
Public Class Form1
Private Sub btnGenerate_Click(sender As Object, e As EventArgs) Handles
[Link]
Dim input As String = InputBox("Enter a number:")
Dim number As Integer
[Link]
using System;
using [Link];
namespace BookVoting
{
public partial class Default : Page
{
private static int goodVotes = 0;
private static int satisfactoryVotes = 0;
private static int badVotes = 0;
private static int totalVotes = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UpdateVoteLabels();
}
}
protected void btnVote_Click(object sender, EventArgs e)
{
if ([Link])
goodVotes++;
else if ([Link])
satisfactoryVotes++;
else if ([Link])
badVotes++;
totalVotes++;
UpdateVoteLabels();
}
private void UpdateVoteLabels()
{
if (totalVotes > 0)
{
[Link] = $"{(goodVotes * 100.0 / totalVotes):0.0}%";
[Link] = $"{(satisfactoryVotes * 100.0 / totalVotes):0.0}%";
[Link] = $"{(badVotes * 100.0 / totalVotes):0.0}%";
}
}
}
}
Output:-
SLIP-20
A) Write a [Link] program to generate Sample Tree View control.
Code:-
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
Dim rootNode As TreeNode = New TreeNode("Root")
Dim childNode1 As TreeNode = New TreeNode("Child 1")
Dim childNode2 As TreeNode = New TreeNode("Child 2")
Dim subChildNode1 As TreeNode = New TreeNode("Sub Child 1")
Dim subChildNode2 As TreeNode = New TreeNode("Sub Child 2")
[Link](subChildNode1)
[Link](subChildNode2)
[Link](childNode1)
[Link](childNode2)
[Link](rootNode)
[Link]()
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.
Code:-
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" Trace="true" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>IndexOutOfRange Exception Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Click the button to generate an IndexOutOfRangeException</h2>
<asp:Button ID="btnTriggerError" runat="server" Text="Trigger Error"
OnClick="btnTriggerError_Click" />
</div>
</form>
</body>
</html>
[Link]
using System;
namespace ErrorHandlingDemo
{
public partial class Default : [Link]
{
protected void btnTriggerError_Click(object sender, EventArgs e)
{
try
{
int[] numbers = { 1, 2, 3 };
int errorValue = numbers[5];
}
catch (IndexOutOfRangeException)
{
[Link]("[Link]");
}
}
}
}
[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Error Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="color: red; font-size: 20px;">
<h2>Oops! An error occurred.</h2>
<p>Something went wrong. Please try again later.</p>
<a href="[Link]">Go Back</a>
</div>
</form>
</body>
</html>
[Link]
using System;
namespace ErrorHandlingDemo
{
public partial class ErrorPage : [Link]
{
protected void Page_Load(object sender, EventArgs e)
}
}
Output:-