0% found this document useful (0 votes)
38 views29 pages

Dot Net Lab Manual1

Uploaded by

aspirantssc892
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)
38 views29 pages

Dot Net Lab Manual1

Uploaded by

aspirantssc892
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/ 29

Experiments

1 Program to display the addition, subtraction, multiplication and division


of two number using console application.

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 Oracle database.

9 Write a program to access data source through ADO.NET.

10 Write a program to manage the session.


Q.1 Program to display the addition, subtraction, multiplication and division of two
numbers using console application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Add_Sub_Mul_Div
{

class Program
{

static void Main(string[] args)


{

int a = 10, b = 4;

Console.WriteLine("Addition = {0}", a + b);

Console.WriteLine("Subtraction = {0}", a - b);

Console.WriteLine("Multiplication = {0}", a * b);

Console.WriteLine("Division = {0}", (float)a / b);

}
}

Output :

Questions :
1. What is the Console.WriteLine() function?
Q.2 Program to display the first 10 natural numbers and their sum using console
application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace First_Ten_No
{

class Program
{

static void Main(string[] args)


{

int s = 0;

for (int i = 1; i <= 10; i++)


{

Console.WriteLine(i);
s = s + i;

}
Console.WriteLine("Sum of Numbers = {0}", s);
}

}
}
Output :
Q.3 Program to display the addition using the windows application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Addition
{

public partial class Form1 : Form


{

public Form1()
{

InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string data1 = textBox1.Text;
string data2 = textBox2.Text;
int a1 = int.Parse(data1);
int a2 = int.Parse(data2);
int a3 = a1 + a2;
textBox3.Text = a3.ToString();
}
}}

Output :
Questions :

1. Why are you using int.Parse() function.

2. Why are you using ToString() function.


Q. 4 Write a program to convert input string from lower to upper and upper to
lower case.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a string in lower case :");
string s1 = Console.ReadLine();

Console.WriteLine("Enter a string in upper case :");


string s2 = Console.ReadLine();

Console.WriteLine("upper case of string {0} is : {1}", s1, s1.ToUpper());


Console.WriteLine("lower case of string {0} is : {1}", s2, s2.ToLower());

}
}
}

Output :
Questions :
1. What is the Console.ReadLine() function?

Q. 5 Write a program to simple calculator using windows application.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Calculator
{
public partial class Form1 : Form
{
string m1, m3, m5, m7, m9;
int x;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "1";

private void button2_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "2";
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "3";
}

private void button4_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "4";
}

private void button5_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "5";
}

private void button6_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "6";
}

private void button7_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "7";
}

private void button8_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "8";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}

private void button10_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "0";
}

private void button11_Click(object sender, EventArgs e)


{
m1 = textBox1.Text;
textBox1.Clear();
x = 1;
}

private void button12_Click(object sender, EventArgs e)


{
m3 = textBox1.Text;
textBox1.Clear();
x = 2;
}

private void button13_Click(object sender, EventArgs e)


{
m5 = textBox1.Text;
textBox1.Clear();
x = 3;
}
private void button14_Click(object sender, EventArgs e)
{
m7 = textBox1.Text;
textBox1.Clear();
x = 4;
}

private void button16_Click(object sender, EventArgs e)


{
textBox1.Clear();
}

private void button15_Click(object sender, EventArgs e)


{
if (x == 1)
{
string m2 = textBox1.Text;
int c = int.Parse(m1) + int.Parse(m2);
textBox1.Text = c.ToString();
}
else if (x == 3)
{
string m4 = textBox1.Text;
int b = int.Parse(m5) - int.Parse(m4);
textBox1.Text = b.ToString();
}
else if (x == 2)
{
string m6 = textBox1.Text;
int d = int.Parse(m3) * int.Parse(m6);
textBox1.Text = d.ToString();
}
else if (x == 4)
{
string m8 = textBox1.Text;
int a1 = int.Parse(m8);
if (a1 == 0)
MessageBox.Show("Can't divide by zero");
else
{
int m = int.Parse(m7) / a1;
textBox1.Text = m.ToString();
}
}
}

private void textBox2_TextChanged(object sender, EventArgs e)


{

private void groupBox1_Enter(object sender, EventArgs e)


{

}
}
}
Output :
Q. 6 Write a program working with Page using ASP.Net.

using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Next Page.aspx");
}
}
Output :
Questions :

1. What is the Response.Redirect() function?


2. What is a difference between Response.Redirect() and Server.Response()?

Q. 7 Write a program working with forms using ASP.NET.

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton1.Checked)
Label3.Text = "Hello Mr." + TextBox1.Text;
else if (RadioButton2.Checked)
Label3.Text = "Hello Ms. " + TextBox1.Text;

}
}

Output :
Questions :
1. What is a ASP.NET.

Q. 8 Write a program to connectivity with Oracle database.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Oracle_form
{
public partial class Form1 : Form
{
OleDbConnection con = new OleDbConnection
("Provider=MSDAORA; User Id=System; Password=manager");

OleDbCommand cmd = new OleDbCommand();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
con.Open();
cmd.Connection = con;

}
private void button1_Click(object sender, EventArgs e)
{

string s = "insert into emp11 values('" + textBox1.Text + " ' , "


+textBox2.Text + ")";

MessageBox.Show(s);

cmd.CommandText = s;
cmd.ExecuteNonQuery();

MessageBox.Show("Information Inserted");
textBox1.Clear();
textBox2.Clear();

Q. 9 Write a program to access data source through ADO.NET.


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

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


{
OleDbConnection con = new OleDbConnection("Provider=MSDAORA;
User Id=result; Password=college");
OleDbCommand cmd = new OleDbCommand();
OleDbCommand cmd1 = new OleDbCommand();
OleDbDataReader dr,dr1;
protected void Page_Load(object sender, EventArgs e)
{
cmd.Connection = con;
cmd1.Connection = con;
con.Open();

string s1 = Session["rollno"].ToString();
string s2 = Session["sem"].ToString();
string s3 = Session["branch"].ToString();

cmd.CommandText = "select * from DATABASE where


ROLLNO='"+s1+"' and SEM='"+s2+"' and BRANCH='"+s3+"' ";
dr = cmd.ExecuteReader();
if (dr.Read())
{

string d1 = dr.GetValue(0).ToString();
string d2 = dr.GetValue(1).ToString();
string d3 = dr.GetValue(2).ToString();
string d4 = dr.GetValue(3).ToString();
string d5 = dr.GetValue(4).ToString();
string d6 = dr.GetValue(5).ToString();
string d7 = dr.GetValue(6).ToString();
string d8 = dr.GetValue(7).ToString();

TextBox1.Text = d1;
TextBox2.Text = d2;
TextBox3.Text = d3;
Label16.Text = d4;
Label17.Text = d5;
Label18.Text = d6;
Label19.Text = d7;
Label20.Text = d8;
dr.Dispose();
}
cmd1.CommandText = "select * from SEM_BRANCH_SUB where
sem='"+s2+"' and branch='"+s3+"' ";
OleDbDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
string d9 = dr1.GetValue(2).ToString();
string d10 = dr1.GetValue(3).ToString();

string d11 = dr1.GetValue(4).ToString();


string d12 = dr1.GetValue(5).ToString();
string d13 = dr1.GetValue(6).ToString();

Label10.Text = d9;
Label11.Text = d10;
Label12.Text = d11;
Label13.Text = d12;
Label14.Text = d13;

}
}
}

Questions :

1. What is a ADO.NET.

Q.10 Write a program to manage the session.


using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)


{

protected void Button1_Click(object sender, EventArgs e)


{

Session["ename"] = TextBox1.Text;
Session["eaddress"] = TextBox2.Text;

Response.Redirect("Default2.aspx");
}

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session.SessionID.ToString();

protected void Button1_Click(object sender, EventArgs e)


{

Session["eage"] = TextBox1.Text;
Session["esalary"] = TextBox2.Text;

Response.Redirect("Default3.aspx");
}

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{

Label1.Text = Session.SessionID.ToString();

TextBox1.Text = Session["ename"].ToString();
TextBox2.Text = Session["eaddress"].ToString();
TextBox3.Text = Session["eage"].ToString();
TextBox4.Text = Session["esalary"].ToString();

Questions :

1. What is the session management.

You might also like