0% found this document useful (0 votes)
2 views

vishu.net

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

vishu.net

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Index

Sr. Title Date Remark Sign


No.
Write a C# program to display Information of student and
1 compile it with csc.exe.
Write a C# program to pass command line arguments:
System. Console.Writelne(), System.Console.Write(),
2
System. Console. Read line() ,System.ConsoleRread(),
System. Console. Readkey ().

Write a C# program for implementation of multiple


main[int,void]
A: - Write a C# program for concatenation of two string [void
main()]
3 B: - Write a C# Program to find given number is even or
odd [int main()]
Write a C# program to check given number is perfect or not,
4 using the "using" keyword.
5 Write a C# program to implement boxing and unboxing.
6 Write a C# program to display information of employee
(members name, address. Age. Date of birth, Basic
pay, hra, da and calculate gross pay.)

Write a C# program to implement C# control


statements (if,for,for each etc).
7
A: - input three number and find which is maximum B: -
input number and find factorial

C: - display the contents of an array of integers using for


each control.
8 Write a C# program to implement casting (Implicit and
explicit).
9 Write a C# program for swapping of two numbers by using
pass by value and pass by reference and out parameters.

10 Write an ASP .NET code to display an Image using image


man control.

11 Write an ASP.NET code to display information of any


industry using hyperlink and image control.
12 Write an Asp. NET code to carry following validation controls:
Required field validations compare
validations
Regular expression validations
Custome Validations
13 Write an ASP.NET code to display Information of
Employee using database as:
Inserting data , Updating data
Deleting data, Display data

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 1 Subject: Dot Net Technology Date:
Title: Write a C# Program to display information of student and compile it with
csc.exe. Remark:

using System;
using System.Data;

class Student
{
private string name;
private int age;
private string grade;

private int rno;

public Student(string name, int rno, int age, string grade)


{
this.name = name;
this.rno = rno;
this.age = age;
this.grade = grade;
}
public void DisplayInfo()
{
Console.WriteLine("Student Information as following:-");
Console.WriteLine("Name: " + name);
Console.WriteLine("Roll No.: " + rno);
Console.WriteLine("Age: " + age);
Console.WriteLine("Grade: " + grade);
}
static void Main(string[] args)
{
Student student = new Student("Vishwajeet Chavan", 2, 19, "A+");
student.DisplayInfo();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}Output:-

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 2 Subject: Dot Net Technology Date:
Title:Write C# program to pass command line argument Remark:
//pass command line argument:-
System.Console.WriteLine(), System.Console.Write(),
System.Console.ReadLine(),System.Console.Read(),
System.Console.ReadKey().
//

Program:-
using System;
class CommandLineArgsExample
{
static void Main(string[] args)

Console.WriteLine("Command Line Arguments Passed:");


foreach (string arg in args)
{
Console.WriteLine(arg);
}
Console.WriteLine("\nThis is Console.WriteLine - It writes the line and
moves to the next.");
Console.Write("This is Console.Write - It writes without moving to the
next line. ");
Console.Write("See? It continues here!");
Console.WriteLine("\n\nPlease enter something using Console.ReadLine:");
string userInput = Console.ReadLine();
Console.WriteLine("You entered: " + userInput);
Console.WriteLine("\nPlease press any key to demonstrate Console.Read:");
int keyAscii = Console.Read();
Console.WriteLine("\nYou pressed (ASCII): " + keyAscii);
Console.WriteLine("\nPress any key to demonstrate Console.ReadKey (it
shows the key you press):");
ConsoleKeyInfo keyInfo = Console.ReadKey();
Console.WriteLine("\nYou pressed: " + keyInfo.Key);
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();
} Output:-

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 3 Subject: Dot Net Technology Date:
Title:Write a C# for implementation of multiple main.[int,void] Remark:

A :- Write a C# program for concentration of two string [void main()].


using System;

class StringConcatenation
{
static void Main()
{

string str1, str2;

Console.WriteLine("Enter the first string:");


str1 = Console.ReadLine();

Console.WriteLine("Enter the second string:");


str2 = Console.ReadLine();

string result = str1 + " " + str2;

Console.WriteLine("Concatenated String: " + result);

Console.WriteLine("Press any key to exit...");


Console.ReadKey();
}
}

Output:-

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 4 Subject: Dot Net Technology Date:
Title:Write a C# for implementation of multiple main.[int,void] Remark:

B :- Write a C# program tyo find number is Odd or Even [int main()].


using System;

class Program
{
static int Main()
{

Console.WriteLine("Enter a number to check if it's odd or even:");

int number;
bool isValid = int.TryParse(Console.ReadLine(), out number);

if (!isValid)
{
Console.WriteLine("Invalid input! Please enter a valid integer.");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return -1;
}

if (number % 2 == 0)
{
Console.WriteLine("The number " + number + " is Even.");
}
else
{
Console.WriteLine("The number " + number + " is Odd.");
}

Console.WriteLine("Press any key to exit...");


Console.ReadKey();

return 0;
}
} Output:-

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 5 Subject: Dot Net Technology Date:
Title:Write a C# program to check given number is perfect or not, using ‘Using’
Keyword. Remark:
using System;
class PerfectNumberCheck
{
static void Main()
{
Console.WriteLine("Enter a number to check if it's a perfect number:");
using (var reader = Console.In)
{
string userInput = reader.ReadLine();
int number;
if (!int.TryParse(userInput, out number) || number <= 0)
{
Console.WriteLine("Please enter a valid positive integer.");
return;
}
bool isPerfect = IsPerfectNumber(number);
Console.WriteLine("The number " + number + " is " + (isPerfect ? "a
perfect number." : "not a perfect number."));
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
static bool IsPerfectNumber(int num)
{
int sum = 0;
for (int i = 1; i < num; i++)
{
if (num % i == 0)
{
sum += i;
}
}
return sum == num;
}
}

Output:-

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 6 Subject: Dot Net Technology Date:
Title: Write a C# program to implement boxing and unboxing Remark:

using System;

class BoxingUnboxing
{
static void Main()
{
int number = 35;
Console.WriteLine("Original value (int): " + number);

object boxedNumber = number; // Boxing


Console.WriteLine("Boxed value (object): " + boxedNumber);

int unboxedNumber = (int)boxedNumber; // Unboxing


Console.WriteLine("Unboxed value (int): " + unboxedNumber);

Console.WriteLine("Original value equals unboxed value: " +


(number == unboxedNumber));

double decimalValue = 3.142;


object boxedDecimal = decimalValue;
Console.WriteLine("Boxed double value: " + boxedDecimal);
double unboxedDecimal = (double)boxedDecimal;
Console.WriteLine("Unboxed double value: " + unboxedDecimal);

Console.WriteLine("Press any key to exit...");


Console.ReadKey();
}
}

Output:-

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 7 Subject: Dot Net Technology Date:
Title: Write a C# program to display information of employee. Remark:

//(name,address,age,date of birth,basicpay,hra,da and calculate gross pay.)


using System;

class Employee
{
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public DateTime DateOfBirth { get; set; }
public decimal BasicPay { get; set; }
public decimal HRA { get; set; }
public decimal DA { get; set; }

public decimal CalculateGrossPay()


{
return BasicPay + HRA + DA;
}
public void DisplayInfo()
{
Console.WriteLine("Employee Information:");
Console.WriteLine("Name: " + Name);
Console.WriteLine("Address: " + Address);
Console.WriteLine("Age: " + Age);
Console.WriteLine("Date of Birth: " +
DateOfBirth.ToShortDateString());
Console.WriteLine("Basic Pay: " + BasicPay);
Console.WriteLine("HRA: " + HRA);
Console.WriteLine("DA: " + DA);
Console.WriteLine("Gross Pay: " + CalculateGrossPay());
}
}
class Program
{
static void Main()
{
Employee employee = new Employee();
Console.Write("Enter Name: ");

employee.Name = Console.ReadLine();
Console.Write("Enter Address: ");

employee.Address = Console.ReadLine();
Console.Write("Enter Age: ");
employee.Age = int.Parse(Console.ReadLine());

Console.Write("Enter Date of Birth (yyyy-mm-dd): ");


employee.DateOfBirth = DateTime.Parse(Console.ReadLine());

Console.Write("Enter Basic Pay: ");


employee.BasicPay = decimal.Parse(Console.ReadLine());
Console.Write("Enter HRA: ");

employee.HRA = decimal.Parse(Console.ReadLine());
Console.Write("Enter DA: ");
employee.DA = decimal.Parse(Console.ReadLine());
employee.DisplayInfo();

Console.WriteLine("Press any key to exit...");


Console.ReadKey();
}
}

Output:-
K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 8 Subject: Dot Net Technology Date:
Title: Write a C# program to implement C# Control Statements(if,for,for……each
etc). Remark:
A.]Input three number and find which is maximum
using System;

class ProgramA
{
static void Main(string[] args)
{
Console.WriteLine("Part A: Enter three numbers:");
Console.Write("Enter first number: ");
int num1 = int.Parse(Console.ReadLine());

Console.Write("Enter second number: ");


int num2 = int.Parse(Console.ReadLine());

Console.Write("Enter third number: ");


int num3 = int.Parse(Console.ReadLine());

int max = num1;

if (num2 > max)


max = num2;

if (num3 > max)


max = num3;

Console.WriteLine("The maximum of the three numbers is: " +


max);
Console.ReadKey();
}
}
Output:-

B.]Input number and find factorial

using System;

class FactorialProgram
{
static void Main(string[] args)
{
Console.Write("Enter a number to find its factorial: ");
int number = int.Parse(Console.ReadLine());

int factorial = 1;

for (int i = 1; i <= number; i++)


{
factorial *= i;
}

Console.WriteLine("The factorial of " + number + " is: " +


factorial);
Console.ReadKey();
}
}
Output:-

C.]Display the contents of array of integer using for each control.


using System;

class DisplayArrayProgram
{
static void Main(string[] args)
{

int[] array = { 5, 10, 15, 20, 25, 30 };

Console.WriteLine("Array contents:");

foreach (int number in array)


{
Console.WriteLine("Number: " + number);
Console.ReadKey();
}
}
}

Output:-
K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 9 Subject: Dot Net Technology Date:
Title: Write a C# program to implement casting (implicit and explicit). Remark:

using System;
class CastingProgram
{
static void Main(string[] args)
{
int intNumber = 150;
double doubleNumber = intNumber;
Console.WriteLine("Implicit Casting:");
Console.WriteLine("Integer value: " + intNumber);
Console.WriteLine("Implicitly casted to double: " +
doubleNumber);

double anotherDouble = 210.78;


int anotherInt = (int)anotherDouble;
Console.WriteLine("\nExplicit Casting:");
Console.WriteLine("Double value: " + anotherDouble);
Console.WriteLine("Explicitly casted to integer (fractional
part lost): " + anotherInt);
string stringNumber = "400";
int parsedNumber = int.Parse(stringNumber);
Console.WriteLine("\nConversion with methods:");
Console.WriteLine("String value: " + stringNumber);
Console.WriteLine("Parsed to integer: " + parsedNumber);
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();
}
}
Output:

K. G. D. B. L. Mahavidyalaya, Kundal
B.C.A- III(2024-25) SEM:V
Name: Roll No.
Assignment no.: 10 Subject: Dot Net Technology Date:
Title: Write a C# program for swapping of two numbers by using pass by value
and pass by reference and out parameters. Remark:

using System;

class SwappingProgram
{

static void SwapByValue(int a, int b)


{
int temp = a;
a = b;
b = temp;
Console.WriteLine("Inside SwapByValue: a = " + a + ", b = " +
b);
}

static void SwapByReference(ref int a, ref int b)


{
int temp = a;
a = b;
b = temp;
}

static void SwapByOut(int a, int b, out int resultA, out int


resultB)
{
resultA = b;
resultB = a;
}

static void Main(string[] args)


{

int x = 11;
int y = 22;

Console.WriteLine("Before SwapByValue: x = " + x + ", y = " +


y);

SwapByValue(x, y);

Console.WriteLine("After SwapByValue: x = " + x + ", y = " +


y);

Console.WriteLine("\nBefore SwapByReference: x = " + x + ", y


= " + y);

SwapByReference(ref x, ref y);

Console.WriteLine("After SwapByReference: x = " + x + ", y = "


+ y);

x = 11;
y = 22;

Console.WriteLine("\nBefore SwapByOut: x = " + x + ", y = " +


y);

int resultX, resultY;


SwapByOut(x, y, out resultX, out resultY);

Console.WriteLine("After SwapByOut: x = " + resultX + ", y = "


+ resultY);

Console.WriteLine("\nPress any key to exit...");


Console.ReadKey();
}
}

Output:-
K. G. D. B. L. Mahavidyalaya, Kundal

B.C.A- III(2024-25) SEM:V


Name: Roll No.
Assignment no.: 11 Subject: Dot Net Technology Date:
Title: Write ASP.NET code to display an image using image map control
Remark:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayImage.aspx.cs"


Inherits="DisplayImage" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
height: 345px;
}

.auto-style2 {
width: 540px;
height: 599px;
margin-left: 167px;
}

</style>
</head>
<body>
<form id="form1" runat="server">
<div></div>
<table class="auto-style1">
<tr> <td>
<asp:ImageMap ID="ImageMap1" runat="server"
ImageUrl="~/Immages/nature.jpg" Width="413px" Height="305px">
<asp:CircleHotSpot />
<asp:RectangleHotSpot Bottom="100" Left="200"
NavigateUrl="~/Employee.aspx" Right="100" Top="200" />
</asp:ImageMap>
</td>
</tr>
</table>
</form>

</body>
</html>

Output:-
K. G. D. B. L. Mahavidyalaya, Kundal

B.C.A- III(2024-25) SEM:V


Name: Roll No.
Assignment no.: 12 Subject: Dot Net Technology Date:
Title: Write ASP.NET code to display information of any industry using
Hyperlink and image control. Remark:

<%@ Page Language="C#" AutoEventWireup="true" Debug="true" %>

<!DOCTYPE html>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)


{

</script>

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Industry Information</title>
<style>
body {
font-family: Arial, sans-
serif; background-color:
#f4f4f4; margin: 0;
padding: 20px;
text-align:
center;
}

.industry-container {
background: #fff;
padding: 20px;
border-radius:
8px;
border: solid
black; margin:
auto; width:
400px;
}

h2
{ color: #333;

}
.industry-image {
width: 80%;
height: auto;
border-radius: 8px;
}

.industry-link {
display: inline-
block; margin-top:
15px; padding: 10px
15px; background-
color: gray; color:
white;
text-
decoration:solid;
border-radius: 4px;
}

.industry-link:hover {
background-color:
gray;
}

.auto-style1 {
width: 357px;
height: 302px;
margin-top:
0px;
}

</style>
</head>
<body>
<form id="form1" runat="server">
<div class="industry-container">
<h2>Tesla Industry</h2>

<br />
<asp:HyperLink ID="image1" runat="server"
NavigateUrl="https://www.tesla.com/" Target="_blank">
<asp:Image ID="image2" runat="server" ImageUrl="Immages/tesla2.jpg"
Width="400px" />
</asp:HyperLink>

<br /> <br />


<asp:HyperLink ID="linkIndustry" runat="server"
NavigateUrl="https://www.tesla.com/" BackColor="#FFFF66" BorderColor="Black"
BorderStyle="Solid" ForeColor="Black" Height="23px" style="font-weight: 700"
Width="128px">Tesla Industry</asp:HyperLink>
<br />
<br />
</div>
</form>
</body>
</html>
Output:-
K. G. D. B. L. Mahavidyalaya, Kundal

B.C.A- III(2024-25) SEM:V


Name: Roll No.
Assignment no.: 13 Subject: Dot Net Technology Date:
Title: Write ASP.NET code to carry following validation controls Remark:
 Required Field Validation
 Compare Validations
 Regular Expression Validations
 Custom Validations

Validation.aspx:-
<%@ Page Language="C#" AutoEventWireup="true" UnobtrusiveValidationMode="None"
Debug="true" %>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Employee Management</title>
<style>
body {
font-family: Arial, sans-
serif; margin: 20px;
height: 414px;
}

label {
display:
block; margin:
5px 0;
}

.error-message {
color: red;
font-size:
12px; margin-
top: 5px;
}

</style>
</head>
<body>
<form id="form1" runat="server">
<h2>Employee Management</h2>

<div>
<label for="txtName">Name:</label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvName" runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required." CssClass="error-message"
Display="Dynamic"></asp:RequiredFieldValidator>
</div>

<div>
<label for="txtAge">Age:</label>
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAge" runat="server"
ControlToValidate="txtAge"
ErrorMessage="Age is required." CssClass="error-message"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revAge" runat="server"
ControlToValidate="txtAge"
ErrorMessage="Enter a valid age." CssClass="error-message"
Display="Dynamic"
ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
</div>

<div>
<label for="txtEmail">Email:</label>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Email is required." CssClass="error-message"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Enter a valid email." CssClass="error-message"
Display="Dynamic"
ValidationExpression="^[\w-\.]+@([\w-]+\.)+[\w-
]{2,4}$"></asp:RegularExpressionValidator>
</div>

<div>
<label for="txtPassword">Password:</label>
<asp:TextBox ID="txtPassword" runat="server"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server"
ControlToValidate="txtPassword"
ErrorMessage="Password is required." CssClass="error-message"
Display="Dynamic"></asp:RequiredFieldValidator>
</div>

<div>
<label for="txtConfirmPassword">Confirm Password:</label>
<asp:TextBox ID="txtConfirmPassword" runat="server"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvConfirmPassword" runat="server"
ControlToValidate="txtConfirmPassword"
ErrorMessage="Confirm Password is required." Display="Dynamic"
ForeColor="#FF6666"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvPassword" runat="server"
ControlToCompare="txtPassword"
ControlToValidate="txtConfirmPassword" ErrorMessage="Passwords do
not match." Display="Dynamic" ForeColor="#FF6600"></asp:CompareValidator>
</div>
<br />
<asp:Button ID="btnSave" runat="server" Text="Save"
OnClick="btnSave_Click" Width="153px" />
<asp:Label ID="lblMessage" runat="server" Visible="False"></asp:Label>

<script runat="server">
protected void btnSave_Click(object sender, EventArgs e)
{

if (Page.IsValid)
{

lblMessage.Text = "Employee " + txtName.Text + " added


successfully! Age: " + txtAge.Text + ", Email: " + txtEmail.Text;
lblMessage.Visible = true;

// Clear the fields after submission


txtName.Text = string.Empty;
txtAge.Text = string.Empty;
txtEmail.Text = string.Empty;
txtPassword.Text = string.Empty;
txtConfirmPassword.Text =
string.Empty;
}

</script>
</form>
</body>
</html>

Output:-
K. G. D. B. L. Mahavidyalaya,
Kundal B.C.A- III(2024-25)
SEM:V

Name: Roll No.


Assignment no.: 1 Subject: Dot Net Technology Date:
Title: Write ASP.NET code to display information of Employee using Remark:
database as:-
 Inserting Data
 Updating Data
 Deleting Data
 Display Data

Employee.aspx:-
<%@ Page Language="C#" AutoEventWireup="true" UnobtrusiveValidationMode="None"
Debug="true" CodeFile="Employee.aspx.cs" Inherits="Employee" %>

<!DOCTYPE html>
<html lang="en">
<head id="Head1" runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Employee Management</title>
<style>
body {
font-family: Arial, sans-
serif; background-color:
#e9ecef; display: flex;
justify-content:
center; align-items:
center; height:
660px;
margin: 0;
}

.container {
background: #ffffff;
padding: 30px;
border: 2px solid
black; border-radius:
10px; width: 400px;
}

h2
{
text-align:
center; margin-
} bottom: 20px;

.form-group {
margin-bottom: 15px; /* Space between text boxes */
}

.error-message {
color: red;
font-size:
12px; margin-
top: 5px;
}

.auto-style1 {
text-align: center;
}

</style>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>Employee Management</h2>

<div class="form-group">
<label for="Id">Id:</label>
<asp:TextBox ID="Id" runat="server" required></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvId" runat="server"
ControlToValidate="Id"
ErrorMessage="Please enter Id." CssClass="error-message"
Display="Dynamic" ValidationGroup="search"></asp:RequiredFieldValidator>
</div>

<div class="form-group">
<label for="txtName">Name:</label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvName" runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required." CssClass="error-message"
Display="Dynamic" ValidationGroup="save"></asp:RequiredFieldValidator>
</div>

<div class="form-group">
<label for="txtAge">Age:</label>
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAge" runat="server"
ControlToValidate="txtAge"
ErrorMessage="Age is required." CssClass="error-message"
Display="Dynamic" ValidationGroup="save"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revAge" runat="server"
ControlToValidate="txtAge"
ErrorMessage="Enter a valid age." CssClass="error-message"
Display="Dynamic"
ValidationExpression="^\d+$"
ValidationGroup="save"></asp:RegularExpressionValidator>
</div>

<div class="form-group">
<label for="ddlGender">Gender:</label>
<asp:DropDownList ID="ddlGender" runat="server"
ValidationGroup="save">
<asp:ListItem Value="">Select Gender</asp:ListItem>
<asp:ListItem Value="Male">Male</asp:ListItem>
<asp:ListItem Value="Female">Female</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvGender" runat="server"
ControlToValidate="ddlGender"
InitialValue="" ErrorMessage="Gender is
required." CssClass="error-message" Display="Dynamic"
ValidationGroup="save"></asp:RequiredFieldValidator>
</div>
<div class="form-group">
<label for="txtCity">City:</label>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCity" runat="server"
ControlToValidate="txtCity"
ErrorMessage="City is required." CssClass="error-message"
Display="Dynamic" ValidationGroup="save"></asp:RequiredFieldValidator>
</div>

<div class="form-group">
<label for="txtEmail">Email:</label>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Email is required." CssClass="error-message"
Display="Dynamic" ValidationGroup="save"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Enter a valid email." CssClass="error-message"
Display="Dynamic"
ValidationExpression="^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"
ValidationGroup="save"></asp:RegularExpressionValidator>
</div>

<div class="form-group">
<label for="txtPassword">Password:</label>
<asp:TextBox ID="txtPassword" runat="server"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server"
ControlToValidate="txtPassword"
ErrorMessage="Password is required." CssClass="error-message"
Display="Dynamic" ValidationGroup="save"></asp:RequiredFieldValidator>
</div>

<div class="form-group">
<label for="txtConfirmPassword">Confirm Password:</label>
<asp:TextBox ID="txtConfirmPassword" runat="server"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvConfirmPassword"
runat="server" ControlToValidate="txtConfirmPassword"
ErrorMessage="Confirm Password is required." CssClass="error-
message" Display="Dynamic" ValidationGroup="save"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvPassword" runat="server"
ControlToCompare="txtPassword"
ControlToValidate="txtConfirmPassword"
ErrorMessage="Passwords do not match." CssClass="error-message"
Display="Dynamic" ValidationGroup="save"></asp:CompareValidator>
</div>

<div class="auto-style1">

<asp:Button ID="btnSave" runat="server" Text="Save"


OnClick="btnSave_Click" ValidationGroup="save" style="text-align: center"
Width="99px"
/>

<br />
<br />
<asp:Label ID="lblMessage" runat="server" ForeColor="Green"
Height="31px" style="margin-top: 0px" Width="82px"></asp:Label>

</div>

<div>
<asp:Button ID="btnSearch" runat="server" Text="Display"
OnClick="btnSearch_Click" ValidationGroup="search" Width="82px" />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;
<asp:Button ID="btnUpdate" runat="server" Text="Update"
OnClick="btnUpdate_Click" ValidationGroup="search" Width="85px" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnDelete" runat="server" Text="Delete"
OnClick="btnDelete_Click" ValidationGroup="search" Width="90px" />
&nbsp;
</div>
</div>
</form>
</body>
</html>

Employee.aspx.cs:-

using System;
using System.Data.SqlClient;
using System.Configuration;

public partial class Employee : System.Web.UI.Page


{

private string connString =


ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

protected void btnSave_Click(object sender, EventArgs e)


{

using (SqlConnection conn = new SqlConnection(connString))


{

string query = "INSERT INTO Employees (Id, Name, Age, Gender, City,
Email, Password) VALUES (@Id, @Name, @Age, @Gender, @City, @Email, @Password)";
using (SqlCommand cmd = new SqlCommand(query, conn))
{

cmd.Parameters.AddWithValue("@Id", Id.Text);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Age", txtAge.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedValue);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);

conn.Open();
cmd.ExecuteNonQuery();

lblMessage.Text = "Employee added successfully."; // Display


messag
success lblMessage.ForeColor = System.Drawing.Color.Green; //
e
Green color for
succes

// Clear input fields after successful


insertion txtName.Text = "";
txtAge.Text = "";
ddlGender.SelectedIndex = 0;
txtCity.Text = "";
txtEmail.Text = "";
txtPassword.Text = "";
txtConfirmPassword.Text =
"";
}
}

// Rest of the code remains unchanged...


protected void btnSearch_Click(object sender, EventArgs e)
{

using (SqlConnection conn = new SqlConnection(connString))


{

conn) SqlCommand cmd = new SqlCommand("SELECT * FROM Employees WHERE Id =


;
@Id", cmd.Parameters.AddWithValue("@Id", Id.Text);

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

if (reader.HasRows)
{

while (reader.Read())
{

txtName.Text =
reader["Name"].ToString(); txtAge.Text =
reader["Age"].ToString();
ddlGender.SelectedValue =
reader["Gender"].ToString(); txtCity.Text =
reader["City"].ToString(); txtEmail.Text =
reader["Email"].ToString();
}

lblMessage.Text = "Employee found.";


} lblMessage.ForeColor = System.Drawing.Color.Green;

els
e
{ ClearFields();
lblMessage.Text = "No employee found with this
ID."; lblMessage.ForeColor =
System.Drawing.Color.Red;
}
conn.Close();
}

private void ClearFields()


{

Id.Text = "";
txtName.Text = "";
txtAge.Text = "";
ddlGender.SelectedIndex = 0;
txtCity.Text = "";
txtEmail.Text = "";
txtPassword.Text = "";
txtConfirmPassword.Text =
"";
}

protected void btnUpdate_Click(object sender, EventArgs e)


{

using (SqlConnection conn = new SqlConnection(connString))

SqlCommand cmd = new SqlCommand("UPDATE Employees SET Name = @Name,


Age = @Age, Gender = @Gender, City = @City, Email = @Email WHERE Id = @Id",
conn);
cmd.Parameters.AddWithValue("@Id", Id.Text);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Age", txtAge.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedValue);
cmd.Parameters.AddWthValue("@City", txtCity.Text);

cmd.Parameters.AddWithValue("@Email", txtEmail.Text);

conn.Open();
int rowsAffected = cmd.ExecuteNonQuery();
conn.Close();

if (rowsAffected > 0)
{

lblMessage.Text = "Record Updated Successfully!";


lblMessage.ForeColor = System.Drawing.Color.Green;
}

els
e lblMessage.Text = "Error: No record found with this ID.";
{ lblMessage.ForeColor = System.Drawing.Color.Red;

protected void btnDelete_Click(object sender, EventArgs e)


{
using (SqlConnection conn = new SqlConnection(connString))
{

SqlCommand cmd = new SqlCommand("DELETE FROM Employees WHERE Id =


conn)
; @Id", cmd.Parameters.AddWithValue("@Id", Id.Text);

conn.Open();
int rowsAffected = cmd.ExecuteNonQuery();
conn.Close();

if (rowsAffected > 0)
{

ClearFields();
lblMessage.Text = "Employee deleted
successfully."; lblMessage.ForeColor =
} System.Drawing.Color.Green;

els
e
{ lblMessage.Text = "No employee found with this
ID."; lblMessage.ForeColor =
System.Drawing.Color.Red;
}

}
Output:-

 Inserting Data:-
 Updating Data:-
 Deleting Data:-
 Display Data:-

You might also like