UNIVERSAL COLLEGE
Maitidevi, Kathmandu
Lab Report of Dotnet Technology
Submitted by: Submitted to:
Shital kumar Awal Mangal Pradhan
BCA 5th
Contents
LAB 1-Write a win form application to show name of 5 different university maintained on
list to a message box. ...................................................................................................................... 3
LAB 2- Write a program to display the use of case when statement to display area of
different types of shape .................................................................................................................. 5
LAB 3- Write a program to create a custom exception class and handle it using different
level of try catch statement. ........................................................................................................... 8
LAB 4 - Write a program to insert, update and delete a record of student into a database in
a Windows Form Based Application. ......................................................................................... 10
LAB 5- Write a program to show list of Employee in Web form application and filter it
using employee name, contact no and email address. ............................................................... 15
LAB 1-Write a win form application to show name of 5
different university maintained on list to a message box.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApp10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] universities = {
"Harvard University",
"Massachusetts Institute of Technology (MIT)",
"Stanford University",
"University of Oxford",
"University of Cambridge"
};
string universitiesText = [Link]("\n", universities);
// Display the list of universities in a message box
[Link](universitiesText, "List of Universities");
}
}
}
Output
LAB 2- Write a program to display the use of case when
statement to display area of different types of shape
using System;
class Program
{
static void Main(string[] args)
{
[Link]("Choose a shape to calculate its area:");
[Link]("1. Circle");
[Link]("2. Rectangle");
[Link]("3. Triangle");
[Link]("Enter your choice (1, 2, or 3):");
int choice = [Link]([Link]());
switch (choice)
{
case 1:
[Link]("Enter the radius of the circle:");
double radius = [Link]([Link]());
double circleArea = [Link] * radius * radius;
[Link]($"Area of the circle: {circleArea}");
break;
case 2:
[Link]("Enter the length of the rectangle:");
double length = [Link]([Link]());
[Link]("Enter the width of the rectangle:");
double width = [Link]([Link]());
double rectangleArea = length * width;
[Link]($"Area of the rectangle: {rectangleArea}");
break;
case 3:
[Link]("Enter the base of the triangle:");
double triangleBase = [Link]([Link]());
[Link]("Enter the height of the triangle:");
double height = [Link]([Link]());
double triangleArea = 0.5 * triangleBase * height;
[Link]($"Area of the triangle: {triangleArea}");
break;
default:
[Link]("Invalid choice!");
break;
}
[Link](); // To prevent the console window from closing immediately
}
}
Output
LAB 3- Write a program to create a custom exception class and
handle it using different level of try catch statement.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApp13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
float num1 = [Link]([Link]);
float num2 = [Link]([Link]);
if (num1 == 0)
throw new MyCustomException("Number cannot be zero");
if (num2 == 0)
throw new DivideByZeroException();
float result = num1 / num2;
[Link] = [Link]();
}
catch (DivideByZeroException)
{
[Link] = "cannot divide by zero";
}
}
}
}
Output
LAB 4 - Write a program to insert, update and delete a record
of student into a database in a Windows Form Based
Application.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=LAPTOP-
I6P5P0C0;Initial Catalog=Student;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=
ReadWrite;MultiSubnetFailover=False");
[Link]();
SqlCommand cmd = new SqlCommand("insert into std values
(@ID,@Name,@Age)", con);
[Link]("@ID", [Link]([Link]));
[Link]("@Name", [Link]);
[Link]("@Age",
[Link]([Link]));
[Link]();
[Link]();
[Link]("Successfully Saved");
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=LAPTOP-
I6P5P0C0;Initial Catalog=Student;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=
ReadWrite;MultiSubnetFailover=False");
[Link]();
SqlCommand cmd = new SqlCommand("Update std set
Name=@Name,Age=@Age where ID =@ID", con);
[Link]("@ID", [Link]([Link]));
[Link]("@Name", [Link]);
[Link]("@Age",
[Link]([Link]));
[Link]();
[Link]();
[Link]("Successfully Updated");
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=LAPTOP-
I6P5P0C0;Initial Catalog=Student;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=
ReadWrite;MultiSubnetFailover=False");
[Link]();
SqlCommand cmd = new SqlCommand("Delete std where ID
=@ID", con);
[Link]("@ID", [Link]([Link]));
[Link]();
[Link]();
[Link]("Successfully Deleted");
}
}
}
OUTPUT
Insert
Update
Delete
LAB 5- Write a program to show list of Employee in Web form
application and filter it using employee name, contact no and
email address.
[Link] designer code
<%@ Page Language=”C#” AutoEventWireup=”true”
CodeBehind=”[Link]”
Inherits=”[Link]” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“[Link]
<html xmlns=”[Link]
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1" runat=”server”>
<h1>WebService Sample</h1>
<div>
<h2>Employee Details fetched using [Link] WebService</h2> </div>
<div>
<asp:GridView ID=”GVEmployeeDetails” runat=”server” CellPadding=”4"
ForeColor=”#333333" GridLines=”None”>
<AlternatingRowStyle BackColor=”White” />
<EditRowStyle BackColor=”#2461BF” />
<FooterStyle BackColor=”#507CD1" Font-Bold=”True” ForeColor=”White” />
<HeaderStyle BackColor=”#507CD1" Font-Bold=”True” ForeColor=”White” />
<PagerStyle BackColor=”#2461BF” ForeColor=”White” HorizontalAlign=”Center” />
<RowStyle BackColor=”#EFF3FB” />
<SelectedRowStyle BackColor=”#D1DDF1" Font-Bold=”True”
ForeColor=”#333333" />
</asp:GridView>
</div>
</form>
</body>
</html>
[Link] Code File
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace SamWebProject
public partial class Home: [Link]
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
BindEmployeeDetails();
}
protected void BindEmployeeDetails()
SamWebService.SamWebService1 objSamWS = new
SamWebService.SamWebService1();
DataSet dsResult = new DataSet();
XmlElement exelement = [Link]();
if (exelement != null)
XmlNodeReader nodeReader = new XmlNodeReader(exelement);
[Link](nodeReader, [Link]);
[Link] = dsResult;
[Link]();
}
Output