Professional Documents
Culture Documents
Lab Manual Dot Net
Lab Manual Dot Net
Lab Manual Dot Net
1. Accept a character from console and check the case of the character.
using System;
class Program
{
static void Main(string[] args)
{
// Step 1: Accept input character from the console
Console.Write("Enter a character: ");
char inputChar = Console.ReadKey().KeyChar;
Console.WriteLine(); // Move to the next line
// Step 2: Check if the input character is lowercase
if (char.IsLower(inputChar))
{
Console.WriteLine("The entered character is in lowercase.");
}
// Step 3: Check if the input character is uppercase
else if (char.IsUpper(inputChar))
{
Console.WriteLine("The entered character is in uppercase.");
}
// Step 4: If the character is neither lowercase nor uppercase, it's not an alphabet character
else
{
Console.WriteLine("The entered character is not an alphabet character.");
}
}
}
Explanation:
1. **Accept Input:** The program prompts the user to enter a character using `Console.Write()` and reads the character
input using `Console.ReadKey().KeyChar`. It stores the input character in the variable `inputChar`.
4. **Output:** Depending on the check results, it prints whether the character is in lowercase, uppercase, or not an
alphabet character using `Console.WriteLine()`.
Enter a character: A
The entered character is in uppercase.
Experiment 2:
2.Write a program to accept any character from the keyboard and display whether it is a vowel or not.
using System;
class Program
{
static void Main(string[] args)
{
// Step 1: Accept input character from the keyboard
Console.Write("Enter a character: ");
char inputChar = Console.ReadKey().KeyChar;
Console.WriteLine(); // Move to the next line
// Step 2: Convert the input character to lowercase for case-insensitive comparison
char lowerChar = char.ToLower(inputChar);
Step 1: Open Visual Studio and Create a new project( Windows Form Application). Give it a Suitable name(Here
we have named it as “NotePad1”).
Step 2: Click on the Create button. You will come across a Form as given below:
Step 3: Change the name of the form from its properties. This will be displayed on the top of the Notepad as its
heading.
From Toolbox, select menu strip and place it on the top in the form area. In MenuStrip, you can provide the names
of the various options that you want in your notepad. We are adding File, Edit, and Format options in the menu.
You can add more as per your choice.
Step 4: Now in the options provided in the MenuBar, we need to have a dialog box that will open up as the user
clicks on the File, Edit, or Font option. Therefore, we will provide further options for them.
rly, for Edit and Font, we will add the options as shown
below:
Step 5: Now we need to add a RichTextBox control from the toolbox in the form so that the user may enter input in
that field. Here, we are not adding a simple textbox because it can basically take single line input whereas
RichTextBox provides more control over styling the text.ll over and covers the notepad screen area completely.
Anchor Property:
Dock property:
Step 6: Now We need to Provide functionality to the various options in the dialog box. For options like Save,
Open, Font, and Color, we need some special controls from the toolbox.
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;
using System.IO;
public Form1()
InitializeComponent();
richTextBox1.Clear();
// to open a file//
{ if(openFileDialog1.ShowDialog()== DialogResult.OK)
{ richTextBox1.Text = File.ReadAllText(openFileDialog1.FileName);
// to save a file //
{ saveFileDialog1.DefaultExt = ".txt";
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
File.WriteAllText(saveFileDialog1.FileName, richTextBox1.Text);
Close();
richTextBox1.Cut();
richTextBox1.Copy();
richTextBox1.Paste();
richTextBox1.SelectAll();
}
Experiment-5
5. Write a program to implement a calculator with memory and recall operations.
Program
using System;
using System.Collections.Generic; using
System.ComponentModel; using System.Data;
using System.Drawing; using
System.Text;
using System.Windows.Forms;
namespace WindowsApplication7
{
public partial class Form1 : Form
{
int n,a,b,r; string op;
public Form1()
{
InitializeComponent();
}
}
private void button2_Click(object sender, EventArgs e)
{
n = int.Parse(textBox1.Text);
textBox1.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = "" + n;
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.AppendText("1");
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.AppendText("2");
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.AppendText("3");
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.AppendText("4");
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.AppendText("5");
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.AppendText("6");
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.AppendText("7");
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.AppendText("8");
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.AppendText("9");
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.AppendText("10");
}
private void button14_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text); op = "+";
textBox1.Clear();
}
private void button15_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text); op = "-";
textBox1.Clear();
}
private void button16_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text); op = "*";
textBox1.Clear();
}
private void button17_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text); op = "/";
textBox1.Clear();
}
private void button18_Click(object sender, EventArgs e)
{
b = int.Parse(textBox1.Text); switch (op)
{
case "+":
r = a + b; textBox1.Text = "" + r;
break;
case "-":
r = a - b;
textBox1.Text = "" + r; break;
case "*":
r = a * b; textBox1.Text = "" + r;
break;
case "/":
r = a / b; textBox1.Text = "" + r;
break;
}
}
}
}
Output
Experiment- 6
6. Develop a form in to pick a date from Calendar control and display the day, month, year details in separate text
boxes.
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 month_calender_using_textbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
textBox1.Text = dateTimePicker1.Value.Day.ToString();
textBox2.Text = dateTimePicker1.Value.Month.ToString();
textBox3.Text = dateTimePicker1.Value.Year.ToString();
}
Open visual studio 2017 ide and go to create project option then click on visual c# windows application with dot net
framework after that create project using project name
Then go to toolbar option select textbox drag and drop into form
And select calendar option from toolbar and drag n drop into form.
Then double click onto calendar then open coding windows then apply code for calendar control.
Output :
Experiment- 7
Design
Program
using System;
using System.Collections.Generic; using
System.ComponentModel; using
System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication6
{
public partial class Form1 : Form
{
string[,] q = new string[10, 4]; string[,]
ans = new string[10, 2]; int i =-1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
q[0, 0] = "WWW stands for";
q[0, 1] = "World Wide Web";
q[0, 2] = "World Wide Web Consortium"; q[0,
3] = "World Web Wide";
q[1, 0] = "XML stands for";
q[1, 1] = "Extended Markup Language"; q[1,
2] = "External Markup Language"; q[1, 3] =
"None";
q[2, 0] = "Pointer is a variable that holds"; q[2, 1] =
"Content";
q[2, 2] = "Data";
q[2, 3] = "Address";
q[3, 0] = "Array is a Collection of"; q[3, 1] =
"Hetrogeneous elements"; q[3, 2] =
"Relational elements";
q[3, 3] = "Homogeneous elements";
q[4, 0] = "CLR executes"; q[4, 1] =
"Managed Code"; q[4, 2] =
"Execution Engine";
q[4, 3] = "Thread Management Unit";
q[5, 0] = "Which one of the following browser ?"; q[5, 1] =
"Visual Basic Managed Code";
q[5, 2] = "Internet Explorer"; q[5, 3]
"C#";
}
private void timer1_Tick(object sender, EventArgs e)
{
i = i + 1; if (i
== 10)
{
radioButton1.Visible = false;
radioButton2.Visible = false;
radioButton3.Visible = false;
timer1.Enabled = false; button1.Enabled =
true; textBox1.Text = "";
}
else
{ radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
textBox1.Text = q[i, 0];
radioButton1.Visible = true;
radioButton2.Visible = true;
radioButton3.Visible = true;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
ans[i, 1] = radioButton2.Text;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
ans[i, 1] = radioButton3.Text;
}
}
}
Output:
Experiment- 8
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 student
{
public partial class Form1 : Form
{
SqlConnection con= new SqlConnection("Data Source =.; Initial Catalog = students; Integrated Security = True");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("insert into student values(@id,@name,@course,@phoneno)",con);
cmd.Parameters.AddWithValue("@id",int.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@name",textBox2.Text);
cmd.Parameters.AddWithValue("@course", textBox3.Text);
cmd.Parameters.AddWithValue("@phoneno",textBox4.Text.ToString());
cmd.ExecuteNonQuery();
//it run the sql statement how many rows effected
con.Close ();
MessageBox.Show("successfully saved");
}
}
}
Experiment- 9
9. Develop a database application using ADO.NET to insert, modify, update and delete operations.
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 student
{
public partial class Form1 : Form
{
SqlConnection con= new SqlConnection ("Data Source =.; Initial Catalog = students; Integrated Security = True");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
cmd.Parameters.AddWithValue ("@id",int.Parse(textBox1.Text));
cmd.Parameters.AddWithValue ("@name",textBox2.Text);
cmd.Parameters.AddWithValue ("@course", textBox3.Text);
cmd.Parameters.AddWithValue("@phoneno", textBox4.Text.ToString());
cmd.ExecuteNonQuery();
//it run the sql statement how many rows effected
con.Close();
MessageBox.Show("successfully updated");
}
Output:
Experiment- 10
10. Develop an application using Data grid to display records.
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 student
{
public partial class Form1 : Form
{
SqlConnection con= new SqlConnection("Data Source =.; Initial Catalog = students; Integrated Security = True");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
void bindata()
{
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 student
{
public partial class Form1 : Form
{
SqlConnection con= new SqlConnection("Data Source =.; Initial Catalog = students; Integrated Security = True");
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
void bindata()
{
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("insert into student values(@id,@name,@course,@phoneno)",con);
cmd.Parameters.AddWithValue("@id",int.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@name",textBox2.Text);
cmd.Parameters.AddWithValue("@course", textBox3.Text);
cmd.Parameters.AddWithValue("@phoneno",textBox4.Text.ToString());
cmd.ExecuteNonQuery();
//it run the sql statement how many rows effected
con.Close ();
bindata();
MessageBox.Show("successfully saved");
}
cmd.Parameters.AddWithValue("@phoneno", textBox4.Text.ToString());
cmd.ExecuteNonQuery();
//it run the sql statement how many rows effected
con.Close();
MessageBox.Show("successfully updated");
}
}
}
Experiment- 12
12. Develop a Window application to read an XML document containing subject, mark scored, and year of
passing into a Dataset.
1. Open visual Studio 2005
2. Click File -> New -> Project -> Visual C# -> Window application
3. On the Right click of solution explorer, Click Add -> New Item -> XML File
4.Type the following XM+L Document
<?xml version="1.0" encoding="utf-8" ?>
<students>
<student>
<name> aswin</naame>
<sub>cbt</sub>
<mark>80</mark>
<yop>2018</yop>
</student>
<student>
<name> arun</naame>
<sub>web</sub>
<mark>90</mark>
<yop>2018</yop>
</student>
</students>
Design
DataGridView Control
Output: