Record C# ASP ADO-1
Record C# ASP ADO-1
using System;
class average
{
public static void Main()
{
int count = 0;
float sum = 0;
Console.WriteLine("Enter the value of n:");
int n = Convert.ToInt32(Console.ReadLine());
while (count < n)
{
Console.WriteLine("Enter the" + count + "number:");
int inp = Convert.ToInt32(Console.ReadLine());
sum += inp;
++count;
}
float average = (float)sum / (n);
Console.WriteLine("\n The Average is \n");
Console.WriteLine(average);
}
}
OUTPUT
INHERITANCE USING ABSTRACT CLASS
using System;
public abstract class Shape
{
public abstract void Draw();
}
public class Rectangle : Shape
{
public override void Draw()
{
Console.WriteLine("Drawing Rectangle");
}
}
public class Circle : Shape
{
public override void Draw()
{
Console.WriteLine("Drawing Circle");
}
}
public class Test
{
public static void Main()
{
Shape S;
S = new Rectangle();
S.Draw();
S = new Circle();
S.Draw();
}
}
OUTPUT
USE OF FOR EACH STATEMENT
using System;
class forea
{
public static void Main(string[] args)
{
char[] gender = { 'm', 'f', 'm', 'm', 'm', 'f', 'f', 'm', 'm', 'f' };
int male = 0, female = 0;
foreach (char g in gender)
{
if (g == 'm')
male++;
else if (g == 'f')
female++;
}
Console.WriteLine("Number of males = {0}", male);
Console.WriteLine("Number of females = {0}", female);
}
}
OUTPUT
OPERATOR OVERLOADING
using System;
class complex
{
double x;
double y;
public complex()
{
}
public complex(double real, double image)
{
x = real;
y = image;
}
public static complex operator +(complex c1, complex c2)
{
complex c3 = new complex();
c3.x = c1.x + c2.x;
c3.y = c1.y + c2.y;
return (c3);
}
public void Display()
{
Console.Write(x);
Console.Write("+j", +y);
Console.WriteLine();
}
}
class complextest
public static void Main()
{
complex a, b, c;
a = new complex(2.5, 3.5);
b = new complex(1.6, 2.7);
c = a + b;
Console.WriteLine("a=");
a.Display();
Console.WriteLine("b=");
b.Display();
Console.WriteLine("c=");
c.Display();
}
}
OUTPUT
EXCEPTION HANDLING
using System;
class exphan
{
public static void Main()
{
int[] a = { 5, 10 };
int b = 5;
try
{
int x = a[2] / b - a[1];
}
catch (ArithmeticException e)
{
Console.WriteLine("Division by zero");
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Array Index Error");
}
catch (ArrayTypeMismatchException e)
{
Console.WriteLine("Wrong Data Type");
}
int y = a[1] / a[0];
Console.WriteLine("y="+y);
}
}
OUTPUT
BASIC WEB SERVER CONTROLS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace sample.aspx
{
public partial class _Default : System.Web.UI.Page
{
protected void lststore_SelectedIndexChanged(object sender, EventArgs e)
{
int index = lststore.SelectedIndex;
TextBox1.Text = " ";
switch (index)
{
case 0:
Image1.ImageUrl = "image/coke.jpg";
Image1.AlternateText = "cola";
break;
case 1:
Image1.ImageUrl = "image/frooti.jpg";
Image1.AlternateText = "frooti";
break;
case 2:
Image1.ImageUrl = "image/pepsi.jpg";
Image1.AlternateText = "pepsi";
break;
case 3:
Image1.ImageUrl = "image/sprite.jpg";
Image1.AlternateText = "sprite";
break;
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
TextBox1.Visible = true;
int index = lststore.SelectedIndex;
switch (index)
{
case 0:
TextBox1.Text = "You have chosen coke and its cost is 30";
break;
case 1:
TextBox1.Text = "You have chosen frooti and its cost is 20";
break;
case 2:
TextBox1.Text = "You have chosen pepsi and its cost is 35";
break;
case 3:
TextBox1.Text = "You have chosen sprite and its cost is 30";
break;
}
}
}
}
SOURCE CODE
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace validator.aspx
{
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox.Text == "100")
Label3.Visible = true;
}
}
}
SOURCE CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace required_val.aspx
{
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid == true)
Label3.Visible = true;
}
}
}
SOURCE CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace pro4.aspx
{
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if (password.Text == confirmpassword.Text)
{
Label9.Visible = true;
Label9.Text = "Successfully registered";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}
}
SOURCE CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
namespace WebApplication5
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
String myconnection = "Provider=Microsoft.ACE.OLEDB.12.0; Data
Source=H:\\Employee.accdb";
OleDbConnection con = new OleDbConnection(myconnection);
con.Open();
string que = "select * from emp";
OleDbCommand que1 = new OleDbCommand(que, con);
OleDbDataReader da = que1.ExecuteReader();
GridView1.DataSource = da;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.End();
}
}
}
}
SOURCE CODE
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;
using System.Data.OleDb;
namespace combo1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=H:\\Payroll.accdb";
string query = "SELECT NAME FROM employee";
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand(query, connection);
{
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
{
while (reader.Read())
{
comboBox1.Items.Add(reader["Name"].ToString());
}
}
}
}
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;
using System.Data.OleDb;
namespace Insert
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
private void button1_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=H:\\Data\\Insert\\Insert\\Student.accdb";
OleDbConnection connection = new OleDbConnection(connectionString);
string insertQuery = "INSERT INTO
Marks(Regno,StudentName,Mark1,Mark2,Mark3,Mark4,Mark5,Class) VALUES ('"
+ textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "', '" +
textBox4.Text + "', '" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text
+ "', '" + textBox8.Text +
"')";
OleDbCommand command = new OleDbCommand(insertQuery, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Record Inserted Successfully");
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
namespace sort.aspx
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
String myconnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=H:\\Stud.accdb";
OleDbConnection conn = new OleDbConnection(myconnection);
conn.Open();
String que = "Select * from student";
OleDbCommand que1 = new OleDbCommand(que, conn);
OleDbDataReader rea = que1.ExecuteReader();
GridView1.DataSource = rea;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.End();
}
}