Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
141 views19 pages

Dotnet Lab

The document contains 5 lab reports on dotnet technology programs. The labs cover creating a windows form application to display university names, calculating area of shapes using case statements, handling custom exceptions, performing CRUD operations on a student database, and filtering a list of employees in a web form application.

Uploaded by

Onil Lamz
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)
141 views19 pages

Dotnet Lab

The document contains 5 lab reports on dotnet technology programs. The labs cover creating a windows form application to display university names, calculating area of shapes using case statements, handling custom exceptions, performing CRUD operations on a student database, and filtering a list of employees in a web form application.

Uploaded by

Onil Lamz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

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 System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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 = string.Join("\n", universities);

// Display the list of universities in a message box


MessageBox.Show(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)
{
Console.WriteLine("Choose a shape to calculate its area:");
Console.WriteLine("1. Circle");
Console.WriteLine("2. Rectangle");
Console.WriteLine("3. Triangle");
Console.WriteLine("Enter your choice (1, 2, or 3):");

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

switch (choice)
{
case 1:
Console.WriteLine("Enter the radius of the circle:");
double radius = double.Parse(Console.ReadLine());
double circleArea = Math.PI * radius * radius;
Console.WriteLine($"Area of the circle: {circleArea}");
break;

case 2:
Console.WriteLine("Enter the length of the rectangle:");
double length = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the width of the rectangle:");
double width = double.Parse(Console.ReadLine());
double rectangleArea = length * width;
Console.WriteLine($"Area of the rectangle: {rectangleArea}");
break;

case 3:
Console.WriteLine("Enter the base of the triangle:");
double triangleBase = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the height of the triangle:");
double height = double.Parse(Console.ReadLine());
double triangleArea = 0.5 * triangleBase * height;
Console.WriteLine($"Area of the triangle: {triangleArea}");
break;

default:
Console.WriteLine("Invalid choice!");
break;
}

Console.ReadLine(); // 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 System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
try
{
float num1 = float.Parse(textBox1.Text);
float num2 = float.Parse(textBox2.Text);
if (num1 == 0)
throw new MyCustomException("Number cannot be zero");
if (num2 == 0)
throw new DivideByZeroException();
float result = num1 / num2;
label3.Text = result.ToString();
}
catch (DivideByZeroException)
{
label3.Text = "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 System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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");
con.Open();
SqlCommand cmd = new SqlCommand("insert into std values
(@ID,@Name,@Age)", con);
cmd.Parameters.AddWithValue("@ID", int.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@Name", textBox2.Text);
cmd.Parameters.AddWithValue("@Age",
double.Parse(textBox1.Text));
cmd.ExecuteNonQuery();

con.Close();
MessageBox.Show("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");
con.Open();
SqlCommand cmd = new SqlCommand("Update std set
Name=@Name,Age=@Age where ID =@ID", con);
cmd.Parameters.AddWithValue("@ID", int.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@Name", textBox2.Text);
cmd.Parameters.AddWithValue("@Age",
double.Parse(textBox1.Text));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("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");
con.Open();
SqlCommand cmd = new SqlCommand("Delete std where ID
=@ID", con);
cmd.Parameters.AddWithValue("@ID", int.Parse(textBox1.Text));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("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.

Home.aspx designer code

<%@ Page Language=”C#” AutoEventWireup=”true”

CodeBehind=”AllEmployeesDetails.aspx.cs”

Inherits=”SamWebProject.AllEmployeesDetails” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”

“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=”http://www.w3.org/1999/xhtml">

<head runat=”server”>

<title></title>

</head>

<body>

<form id=”form1" runat=”server”>

<h1>WebService Sample</h1>

<div>

<h2>Employee Details fetched using Asp.Net 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>
Home.aspx Code File

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Xml;

namespace SamWebProject

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

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 = objSamWS.GetAllEmployeesDetails();

if (exelement != null)

XmlNodeReader nodeReader = new XmlNodeReader(exelement);

dsResult.ReadXml(nodeReader, XmlReadMode.Auto);

GVEmployeeDetails.DataSource = dsResult;

GVEmployeeDetails.DataBind();

}
Output

You might also like