0% found this document useful (0 votes)
30 views17 pages

SQL and ASP.NET Programming Lab Guide

Uploaded by

YOGENDRA
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)
30 views17 pages

SQL and ASP.NET Programming Lab Guide

Uploaded by

YOGENDRA
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

LAB FILE

[Link]
(UCS4502SE)

SUBMITTED BY: SUBMITTED TO:


ABHAY PRATAP SINGH Dr. Archana Maurya
202210101330005
BCA(AI)-41
INDEX

[Link] 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


[Link].

7. Write a program working with forms using


[Link].

8. Write a program to connectivity with


Microsoft sql database.

9. Write a program to access data source


through [Link]

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()

[Link]("Enter first number: ");

double num1 = [Link]([Link]());

[Link]("Enter second number: ");

double num2 = [Link]([Link]());

double addition = num1 + num2;

double subtraction = num1 - num2;

double multiplication = num1 * num2;

double division = num1 / num2;

[Link]("Addition: " + addition);

[Link]("Subtraction: " + subtraction);

[Link]("Multiplication: " + multiplication);

[Link]("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++)
{
[Link]("Natural Number " + i + " : " + i);
sum += i;
}
[Link]("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 [Link];

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

private void button1_Click(object sender, EventArgs e)


{
int num1 = [Link]([Link]);
int num2 = [Link]([Link]);
int sum = num1 + num2;

[Link]("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()
{
[Link]("Enter a string: ");
string input = [Link]();

string uppercase = [Link]();


string lowercase = [Link]();

[Link]("Uppercase: " + uppercase);


[Link]("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;
[Link] = [Link] + [Link];
}
private void button_Clear_Click(object sender, EventArgs e)
{
[Link]();
}
private void button_Addition_Click(object sender, EventArgs e)
{
num1 = [Link]([Link]);
[Link]();
[Link]();
operation = 1;
}

private void button_Subtraction_Click(object sender, EventArgs e)


{
num1 = [Link]([Link]);
[Link]();
[Link]();
operation = 2;
}

private void button_Multiplication_Click(object sender, EventArgs e)


{
num1 = [Link]([Link]);
[Link]();
[Link]();
operation = 3;
}

private void button_Division_Click(object sender, EventArgs e)


{
num1 = [Link]([Link]);
[Link]();
[Link]();
operation = 4;
}
private void button_Equals_Click(object sender, EventArgs e)
{
num2 = [Link]([Link]);

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

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

<h1>Welcome to my [Link] Core Razor Page!</h1>


<p>Current date and time is: @[Link]()</p>
using [Link];
using [Link];
using System;

namespace [Link]
{
public class IndexModel : PageModel
{
public DateTime CurrentDateTime { get; set; }

public void OnGet()


{
CurrentDateTime = [Link];
}
}
}
Output-
Lab 7-
Write a program working with forms using [Link].

Source Code-
using [Link];

namespace [Link]
{
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 [Link]

<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 [Link];

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))
{
[Link]();
[Link]("Connection open!");
[Link]();
}
}
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
[Link]();
string query = "SELECT * FROM TableName WHERE ColumnName = @param";
SqlCommand command = new SqlCommand(query, connection);
[Link](new SqlParameter("param", value));
SqlDataReader reader = [Link]();
while ([Link]())
{
[Link]([Link]("{0}\t|{1}\t|{2}", reader[0], reader[1], reader[2]));
}
[Link]();
[Link]();
}
Output-
Lab 9-
Write a program to access data source through [Link]

Source Code-
using System;
using [Link];

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))
{
[Link]();
[Link]("Connection open!");
string query = "SELECT * FROM TableName";
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = [Link]();
while ([Link]())
{
[Link]([Link]("{0}\t|{1}\t|{2}", reader[0], reader[1],
reader[2]));
}
[Link]();
[Link]();
}
}
}
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 [Link];
using [Link];
using [Link];

namespace [Link]
{
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 ([Link])
{
// Save the feedback to a database or send it via email
[Link]("Name: " + Name);
[Link]("Email: " + Email);
[Link]("Message: " + Message);
}
}
}
}
Output-

Common questions

Powered by AI

ADO.NET retrieves data from a SQL database using SqlConnection to establish a connection to the database and SqlCommand to execute SQL queries. The execution of queries fetches data through SqlDataReader, which provides fast, forward-only, read-only retrieval of data from data sources . Closing the SqlDataReader and SqlConnection ensures resource management and performance optimization . These objects collectively enable efficient data access and manipulation in ADO.NET applications .

ADO.NET provides a robust platform for database connectivity by offering a disconnected architecture with DataSets, or direct access through DataReader objects, which offers optimized data retrieval. ADO.NET supports a variety of databases and offers extensive connection management, making it ideal for large-scale applications . Compared to ORMs like Entity Framework, ADO.NET typically provides higher performance and more granular control over SQL queries and transactions, but it requires more manual management of connection state and data handling .

Razor Pages in ASP.NET offer a page-focused model, streamlining the development of web applications by organizing files around each functionality or page. Each Razor Page has an associated PageModel, which corresponds to the controller in traditional MVC, handling requests and actions specific to the page . Unlike MVC, which separates applications into Controllers, Views, and Models, Razor Pages encourage a more cohesive structure by coupling the behavior and rendering inside a single file structure .

The ASP.NET MVC framework handles form validation using data annotations on model properties. Essential components include attributes like [Required], [StringLength], and [EmailAddress], which specify validation rules directly in the model classes . This ensures that client-side validations, as well as server-side validations, are executed when forms are submitted. The framework uses ModelState to track validation errors and provides validation helpers to display these errors on the view .

Creating a feedback form in ASP.NET involves modeling form data with attributes for validation such as [Required] and [EmailAddress], and using Razor syntax for embedding validation logic in views . Client-side validation is critical as it enhances user experience by providing immediate feedback, reducing server load by catching errors before data submission, and preventing unnecessary requests to the server for validation errors that can be identified locally . It leverages scripts to perform validation checks in real-time, ensuring data integrity and responsiveness .

Potential challenges with using ADO.NET for SQL database connectivity include managing connection lifecycles, connectivity issues from incorrect configurations, and risk of SQL injection if queries are improperly handled . These can be mitigated by employing using blocks for automatic disposal of connections, validating connection strings, using parameterized queries to prevent injection attacks, and robust exception handling to capture and manage runtime errors effectively . Ensuring secure password storage and connection encryption also enhances security .

To create a simple Windows Forms application for arithmetic operations, start by designing the form with TextBox controls for input and buttons for operations like addition, subtraction, multiplication, and division. Implement event handlers for these buttons to parse the input from the TextBoxes, perform the arithmetic, and display the results. Utilize event handlers like button_Click to capture inputs and display outputs using MessageBox.Show .

A Windows Forms calculator app enhances user interaction over a console application by offering graphical user interface elements like buttons for numbers and operations, textboxes for input and output, and message dialogs for results . This allows for mouse interactions and intuitive operations that are more visually engaging than text-based console input/output, improving usability especially for non-technical users .

The essential features for creating a feedback form in ASP.NET Razor Pages include defining a PageModel class with properties for Name, Email, and Message, each decorated with data annotations for validation such as [Required], [EmailAddress], and [StringLength]. The form tag uses method="post" for secure data transmission, while the asp-validation-summary and asp-validation-for helpers are used to display validation errors directly in the view . This ensures effective data collection with client-side and server-side validation .

In C#, string manipulation for case conversion can be achieved using methods like ToUpper() and ToLower() on string objects, transforming all characters in the string to uppercase or lowercase, respectively . This manipulation is useful in scenarios like normalizing user input data for comparison, ensuring consistency in display, and preparing data for case-sensitive operations .

You might also like