You are on page 1of 17

LAB FILE

ASP.NET
(UCS4502SE)

SUBMITTED BY: SUBMITTED TO:


ADARSH PATEL Mr. JULIUS KUMAR
202210101330027
BCA(AI)-41
INDEX

S.NO Name of Experiment Date Faculty signature Remarks


Program to display the addition, subtraction,
1. multiplication and division of two number
using console applications
2. Program to display the first 10 natural
numbers and their sum using console
application

3. Program to display the addition using the


windows application.

4. Write a program to convert input string


from lower to upper and upper to lower case

5. Write a program to simple calculator using


windows application.

6. Write a program working with Page using


ASP.Net.

7. Write a program working with forms using


ASP.NET.

8. Write a program to connectivity with


Microsoft sql database.

9. Write a program to access data source


through ADO.NET

10. Write a program to display the following


feedback form.
Lab 1-
Program to display the addition, subtraction, multiplication and division of two number using
console applications

Source Code-
using System;

class Program

static void Main()

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

double num1 = Convert.ToDouble(Console.ReadLine());

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

double num2 = Convert.ToDouble(Console.ReadLine());

double addition = num1 + num2;

double subtraction = num1 - num2;

double multiplication = num1 * num2;

double division = num1 / num2;

Console.WriteLine("Addition: " + addition);

Console.WriteLine("Subtraction: " + subtraction);

Console.WriteLine("Multiplication: " + multiplication);

Console.WriteLine("Division: " + division);

}
}
Output-
Lab 2-
Program to display the first 10 natural numbers and their sum using console application

Source Code-
using System;

class Program
{
static void Main()
{
int sum = 0;
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("Natural Number " + i + " : " + i);
sum += i;
}
Console.WriteLine("Sum of the first 10 natural numbers: " + sum);
}
}
Output-
Lab 3-
Program to display the addition using the windows application.

Source Code-
using System;
using System.Windows.Forms;

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

private void button1_Click(object sender, EventArgs e)


{
int num1 = int.Parse(textBox1.Text);
int num2 = int.Parse(textBox2.Text);
int sum = num1 + num2;

MessageBox.Show("The sum is: " + sum);


}
}
}
Output-
Lab 4-
Write a program to convert input string from lower to upper and upper to lower case

Source Code-
using System;

class Program
{
static void Main()
{
Console.Write("Enter a string: ");
string input = Console.ReadLine();

string uppercase = input.ToUpper();


string lowercase = input.ToLower();

Console.WriteLine("Uppercase: " + uppercase);


Console.WriteLine("Lowercase: " + lowercase);
}
}
Output-
Lab 5-
Write a program to simple calculator using windows application.

Source Code-
private void button_Number_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
textBox1.Text = textBox1.Text + button.Text;
}
private void button_Clear_Click(object sender, EventArgs e)
{
textBox1.Clear();
}
private void button_Addition_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
operation = 1;
}

private void button_Subtraction_Click(object sender, EventArgs e)


{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
operation = 2;
}

private void button_Multiplication_Click(object sender, EventArgs e)


{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
operation = 3;
}

private void button_Division_Click(object sender, EventArgs e)


{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
operation = 4;
}
private void button_Equals_Click(object sender, EventArgs e)
{
num2 = float.Parse(textBox1.Text);

switch (operation)
{
case 1:
textBox1.Text = (num1 + num2).ToString();
break;
case 2:
textBox1.Text = (num1 - num2).ToString();
break;
case 3:
textBox1.Text = (num1 * num2).ToString();
break;
case 4:
textBox1.Text = (num1 / num2).ToString();
break;
}
}
float num1, num2, operation;
Output-
Lab 6-
Write a program working with Page using ASP.Net.

Source Code-
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}

<h1>Welcome to my ASP.NET Core Razor Page!</h1>


<p>Current date and time is: @Model.CurrentDateTime.ToString()</p>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;

namespace MyApp.Pages
{
public class IndexModel : PageModel
{
public DateTime CurrentDateTime { get; set; }

public void OnGet()


{
CurrentDateTime = DateTime.Now;
}
}
}
Output-
Lab 7-
Write a program working with forms using ASP.NET.

Source Code-
using System.ComponentModel.DataAnnotations;

namespace SimpleFormApp.Models
{
public class ContactModel
{
[Required(ErrorMessage = "Please enter your name.")]
[StringLength(50, ErrorMessage = "Name cannot be longer than 50 characters.")]
public string Name { get; set; }

[Required(ErrorMessage = "Please enter your email address.")]


[EmailAddress(ErrorMessage = "Invalid email address.")]
public string Email { get; set; }

[Required(ErrorMessage = "Please enter your message.")]


[StringLength(200, ErrorMessage = "Message cannot be longer than 200 characters.")]
public string Message { get; set; }
}
}
@model SimpleFormApp.Models.ContactModel

<form asp-action="Contact" method="post">


<div asp-validation-summary="ModelOnly"></div>
<div>
<label asp-for="Name"></label>
<input asp-for="Name" />
<span asp-validation-for="Name"></span>
</div>
<div>
<label asp-for="Email"></label>
<input asp-for="Email" />
<span asp-validation-for="Email"></span>
</div>
<div>
<label asp-for="Message"></label>
<textarea asp-for="Message"></textarea>
<span asp-validation-for="Message"></span>
</div>
<div>
<input type="submit" value="Submit" />
</div>
</form>
Output-
Lab 8-
Write a program to connectivity with Microsoft sql database.

Source Code-
using System;
using System.Data.SqlClient;

class Program
{
static void Main()
{
string connectionString = @"Data Source=WIN-50GP30FGO75;Initial
Catalog=Demodb;User ID=sa;Password=demol23";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("Connection open!");
connection.Close();
}
}
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string query = "SELECT * FROM TableName WHERE ColumnName = @param";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add(new SqlParameter("param", value));
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}\t|{1}\t|{2}", reader[0], reader[1], reader[2]));
}
reader.Close();
connection.Close();
}
Output-
Lab 9-
Write a program to access data source through ADO.NET

Source Code-
using System;
using System.Data.SqlClient;

class Program
{
static void Main()
{
string connectionString = @"Data Source=WIN-50GP30FGO75;Initial
Catalog=Demodb;User ID=sa;Password=demol23";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("Connection open!");
string query = "SELECT * FROM TableName";
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}\t|{1}\t|{2}", reader[0], reader[1],
reader[2]));
}
reader.Close();
connection.Close();
}
}
}
Output-
Lab 10-
Write a program to display the following feedback form.

Source Code-
@page
@model FeedbackModel
@{
ViewData["Title"] = "Feedback";
}

<h1>Feedback Form</h1>
<form method="post">
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name"></span>
</div>
<div class="form-group">
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email"></span>
</div>
<div class="form-group">
<label asp-for="Message"></label>
<textarea asp-for="Message" class="form-control"></textarea>
<span asp-validation-for="Message"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace FeedbackApp.Pages
{
public class FeedbackModel : PageModel
{
[Required]
[StringLength(50)]
public string Name { get; set; }

[Required]
[EmailAddress]
public string Email { get; set; }

[Required]
[StringLength(200)]
public string Message { get; set; }

public void OnPost()


{
if (ModelState.IsValid)
{
// Save the feedback to a database or send it via email
Console.WriteLine("Name: " + Name);
Console.WriteLine("Email: " + Email);
Console.WriteLine("Message: " + Message);
}
}
}
}
Output-

You might also like