100% found this document useful (1 vote)
78 views19 pages

Dotnet Lab Report for BCA Students

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
100% found this document useful (1 vote)
78 views19 pages

Dotnet Lab Report for BCA Students

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

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

Common questions

Powered by AI

Initializing a database connection in multiple event handlers can lead to inefficient resource use and increased latency, as each initialization incurs overhead. This practice can degrade application performance, especially under heavy load. Best practices to optimize this include using connection pooling, which reuses existing connections, thus reducing the cost of opening and closing connections. Implementing centralized database connection management, where a single connection instance is reused across different operations, also optimizes resource usage and improves performance .

Incorrectly implementing 'DivideByZeroException' can significantly affect user experience and program reliability. If this exception is not correctly caught, the application could crash when a division by zero occurs, leading to a loss of user data and diminished trust in the application's reliability. This exception should be handled appropriately, displaying user-friendly error messages, such as 'cannot divide by zero,' to guide the user towards correct input, thus enhancing the overall usability and robustness of the application .

Filtering employee data based on specific fields demonstrates query optimization principles by minimizing the dataset retrieved from the database, thereby reducing processing time and resource usage. Effective query optimization involves constructing efficient SQL queries that leverage indexes and reduce the number of rows returned by the query, which decreases the load on both the database server and the web server. In the ASP.NET framework, leveraging LINQ or ORM tools enhances query optimization by generating optimized queries that abstract complex SQL logic, thus improving application responsiveness and scalability .

Data integrity in a Windows Form application managing database records can be ensured through input validation, transaction management, and exception handling. Structured Query Language (SQL) statements should use parameterized queries to prevent SQL injection. For example, SqlCommand.Parameters.AddWithValue is used to safely insert user input into SQL commands, ensuring that user input is treated as data, not executable code. Additionally, transactions can be used to maintain data consistency, ensuring that a set of SQL operations completes successfully before committing changes to the database .

The implementation of displaying university names using Windows Forms demonstrates object-oriented programming principles such as encapsulation and abstraction. The application creates a Windows Form where logic is encapsulated within the class Form1. Methods like InitializeComponent and button1_Click encapsulate setup and event handling logic, abstracting away complex implementation details from the user. When the display button is clicked, an event is triggered, executing encapsulated code to display a list of universities in a message box, showcasing how encapsulation and event-driven programming are vital in ensuring maintainable and scalable code .

Data binding plays a crucial role in the GridView functionality by linking a data source to the control, facilitating dynamic content management. It allows the automatic population of GridView rows with data from sources like databases or XML files, handling data presentation seamlessly. This linkage helps dynamically update content without manual row-by-row processing or page refreshes, improving responsiveness and user interaction. Additionally, data binding simplifies the integration of filtering and sorting functionalities, enhancing the user experience in web applications .

Handling various data types in a database-oriented application poses challenges regarding type safety, conversion, and validation. Ensuring accurate data processing requires strategies like using strongly-typed parameters in SQL commands and implementing validation logic to handle user inputs before they reach the database. Type mismatches can be prevented by clearly defining expected data types at both the application and database levels and ensuring that data manipulations respect these constraints. Frameworks that support ORM can further enhance type safety by mapping database types to application-specific objects, reducing the likelihood of runtime errors .

Custom exception classes in a Windows application enable more specific and meaningful error handling compared to built-in exceptions. By defining a custom exception, developers can create exception handling specific to their application's domain, enriching error messages with context-relevant details and allowing for more refined catch blocks. For instance, throwing a MyCustomException when a specific business logic rule is violated provides precise information on the nature of the issue, facilitating debugging and maintenance . This specificity improves code readability and maintainability by preventing generic error messages, which may not provide sufficient context for resolution.

ASP.NET Web Forms are effective for displaying employee details due to their rapid development features and rich control set. The use of controls like GridView facilitates quick data binding and presentation, allowing developers to implement complex filtering functionalities with minimal code. However, potential limitations include limited control over the HTML output and performance issues in large data sets due to the ViewState feature. Additionally, as the web moves towards more modern frameworks like ASP.NET Core and client-side frameworks, Web Forms may lack the flexibility and responsiveness required for contemporary web applications .

Using the 'case when' statement for calculating shape areas in a console application can introduce complexity and reduce scalability. Each case requires specific input handling and computations, which could result in verbose and repetitive code when additional shapes or calculations are added in the future. Additionally, error handling is more challenging, as input validation and exception management must be explicitly coded, increasing the risk of errors if not carefully managed .

You might also like