0% found this document useful (0 votes)
40 views42 pages

Record C# ASP ADO-1

The document shows how inheritance can be used to implement polymorphism through an abstract base class in C#. An abstract Shape class defines a Draw method but does not provide an implementation. Rectangle and Circle classes inherit from Shape and override the Draw method, providing class-specific drawing logic. The main method creates Shape references to Rectangle and Circle objects and calls their

Uploaded by

raziyabanu2105
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)
40 views42 pages

Record C# ASP ADO-1

The document shows how inheritance can be used to implement polymorphism through an abstract base class in C#. An abstract Shape class defines a Draw method but does not provide an implementation. Rectangle and Circle classes inherit from Shape and override the Draw method, providing class-specific drawing logic. The main method creates Shape references to Rectangle and Circle objects and calls their

Uploaded by

raziyabanu2105
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/ 42

AVERAGE OF N NUMBERS

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

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="sample.aspx._Default"
%>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Medium"
ForeColor="#660033" Text="BASIC WEBSERVER CONTROL"></asp:Label>
<asp:ListBox ID="lststore" runat="server" AutoPostBack="True" Height="136px"
onselectedindexchanged="lststore_SelectedIndexChanged" Width="136px">
<asp:ListItem>coke</asp:ListItem>
<asp:ListItem>frooti</asp:ListItem>
<asp:ListItem>pepsi</asp:ListItem>
<asp:ListItem>sprite</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:ListBox>
<asp:Image ID="Image1" runat="server" Width="146px" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="cost"
Width="97px" />
<asp:TextBox ID="TextBox1" runat="server"
ontextchanged="TextBox1_TextChanged" style="margin-bottom: 1px"
Width="257px">you have chosen pepsi and its cost is 35
</asp:TextBox>
</asp:Content>
OUTPUT
COMPARE VALIDATOR

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

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="validator.aspx._Default"
%>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large"
ForeColor="#0000CC" Text="USAGE OF COMPARE VALIDATIOR">
</asp:Label>
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Black"
Text="ENTER THE BOILING POINT OF WATER">
</asp:Label>
<asp:TextBox ID="TextBox" runat="server" ontextchanged="TextBox_TextChanged">
</asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="please enter the correct boiling point" ValueToCompare="100"
ControlToValidate="TextBox">
</asp:CompareValidator>
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Size="Medium"
Height="28px" onclick="Button1_Click" Text="click" />
<asp:Label ID="Label3" runat="server" Font-Italic="True" Font-Size="Medium"
ForeColor="Black" Text="YOU HAVE ENTERED THE CORRECT BOILING
POINT" Visible="False"></asp:Label>
</asp:Content>
OUTPUT
REQUIRED FIELD VALIDATOR

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

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="required_val.aspx._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large"
ForeColor="#660033" Text="REQUIRED FIELD VALIDATION"></asp:Label>
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="Medium"
ForeColor="#9966FF" Text="ENTER THE NAME"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="please enter the name">
</asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Font-Bold="True"
onclick="Button1_Click" Text="SUBMIT" />
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Medium"
ForeColor="Black" Text="YOU HAVE ENTERED THE CORRECT NAME"
Visible="False"></asp:Label>
</asp:Content>
OUTPUT
REGISTRATION FORM

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

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="pro4.aspx._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Text="REGISTRATION FORM"
Font-Bold="True"> </asp:Label>
<asp:Label ID="Label2" runat="server" Text="USERNAME"></asp:Label>
<asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="username" ErrorMessage="Please enter username"
Font-Bold="True" Font-Size="Large" ForeColor="Red">
</asp:RequiredFieldValidator>
<asp:Label ID="Label3" runat="server" Text="PASSWORD"></asp:Label>
<asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="password" ErrorMessage="Please enter password"
Font-Bold="True" Font-Size="Large" ForeColor="Red">
</asp:RequiredFieldValidator>
<asp:Label ID="Label4" runat="server" Text="CONFIRM PASSWORD">
</asp:Label>
<asp:TextBox ID="confirmpassword" runat="server" TextMode="Password">
</asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="password" ControlToValidate="confirmpassword"
ErrorMessage="Password does not match" Font-Bold="True" Font-Size="Large"
ForeColor="Red"></asp:CompareValidator>
<asp:Label ID="Label5" runat="server" Text="AGE"></asp:Label>
<asp:TextBox ID="Age" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="Age" ErrorMessage="Please enter your Age"
Font-Bold="True" Font-Size="Large" ForeColor="Fuchsia">
</asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="Age"
ErrorMessage="Please enter age between 20 and 40" MaximumValue="40"
MinimumValue="20" Type="Integer" Font-Bold="True" Font-Size="Large"
ForeColor="Red"> </asp:RangeValidator>
<asp:Label ID="Label8" runat="server" Text="Sex"></asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Gender"
Text="Male" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Gender"
Text="Female" />
<asp:Label ID="Label6" runat="server" Text="EMAIL ID"></asp:Label>
<asp:TextBox ID="emailid" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server"
ErrorMessage="Please enter Email id" ControlToValidate="emailid"
Font-Bold="True" Font-Size="Large" ForeColor="#6600FF">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server" ControlToValidate="emailid"
EnableClientScript="False" ErrorMessage="mail id upto 20 characters "
Font-Bold="True" Font-Size="Large" ForeColor="#9900CC"
ValidationExpression="&quot;\s{20}&quot;" Visible="False">
</asp:RegularExpressionValidator>
<asp:Label ID="Label7" runat="server" Text="CITY"></asp:Label>
<asp:ListBox ID="city" runat="server" AutoPostBack="True">
<asp:ListItem>Bangalore</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Delhi</asp:ListItem>
<asp:ListItem>Mumbai</asp:ListItem>
<asp:ListItem>Agra</asp:ListItem>
<asp:ListItem>Gujarat</asp:ListItem>
<asp:ListItem>kolkatta</asp:ListItem>
</asp:ListBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="choose ur city" ControlToValidate="city"
Font-Bold="True" Font-Size="Large" ForeColor="Blue"></asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Font-Size="Larger"
onclick="Button1_Click" Text="SUBMIT" Width="216px" />
<asp:Label ID="Label9" runat="server" Font-Bold="True" Font-Size="Smaller"
ForeColor="#0000CC" Visible="False">successfully registered</asp:Label>
<asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Size="Small"
Visible="False"></asp:Label>
<asp:Button ID="Button2" runat="server" Font-Bold="True" Font-Size="Larger"
onclick="Button2_Click" Text="Exit" Width="204px" />
</asp:Content>
OUTPUT
DATA GRID VIEW

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

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication5.Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large"
Text="EMPLOYEE LIST" ForeColor="Black"></asp:Label>
<asp:GridView ID="GridView1" runat="server" Font-Bold="True"
Font-Size="X-Large"
onselectedindexchanged="GridView1_SelectedIndexChanged">
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server">
</asp:AccessDataSource>
</asp:Content>
OUTPUT
BINDING COMBO

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

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=H:\\Payroll.accdb ";
string query = "SELECT * FROM employee where Name='" + comboBox1.Text
+"'";
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand(query, connection);
{
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
{
while (reader.Read())
{
string No = reader.GetInt32(0).ToString();
string Name = reader.GetString(1);
string Designation = reader.GetString(2);
string Department = reader.GetString(3);
noTextBox.Text = No;
nameTextBox.Text = Name;
designationTextBox.Text = Designation;
departmentTextBox.Text = Department;
comboBox1.Text = Name;
}
}
}
}
}
}
OUTPUT
INSERTING

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");
}

private void button2_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);
int DelReg;
if (int.TryParse(textBox1.Text, out DelReg))
{
string deleteQuery = "DELETE FROM Marks WHERE Regno = ?";
OleDbCommand command = new OleDbCommand(deleteQuery, connection);
command.Parameters.Add("Regno", OleDbType.Integer).Value = DelReg;
connection.Open();
int rows = command.ExecuteNonQuery();
connection.Close();
if (rows > 0)
MessageBox.Show("Record deleted successfully.");
else
MessageBox.Show("Record not found or couldn't be deleted.");
}
else
{
MessageBox.Show("Invalid input for Regno. Please enter a valid integer.");
}
}
}
}
OUTPUT
SORTING

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

protected void Button1_Click(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 stud order by name";
OleDbCommand que1 = new OleDbCommand(que, conn);
OleDbDataReader rea = que1.ExecuteReader();
GridView1.DataSource = rea;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.End();
}
}
}
}
SOURCE CODE

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="sort.aspx._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial Black"
Font-Size="Large" ForeColor="#000099" Text="STUDENT INFORMATION">
</asp:Label>
<asp:GridView ID="GridView2" runat="server" Height="224px" Width="497px">
</asp:GridView>
<asp:Button ID="Button2" runat="server" Font-Bold="True" Font-Size="Medium"
Text="SORT" onclick="Button2_Click1" />
</asp:Content>
OUTPUT

You might also like