Sie sind auf Seite 1von 22

Program to implement GET method using Servlet.

Program to implement POST method using Servlet


Program to implement various Request methods using Servlet.
Program to implement Counter using Servlet
Program to implement session management using servlet
Program to check username and password are valid or not using Servlet.
Program to create page visit Counter using the JSP
Program to implement various attributes of page directives using the JSP
Program to implement Jsp:forward & Jsp:param Standard actions
Program to convert temperature from Fahrenheit to Celsius using JSP
Write a JSP program to access your machine address.
Program to implement Command line arguments using C#
Program to implement maths operations using C#
Program to implement Jagged Array using C#
Write a Program to create text file using C#
Write a C# program to find out simple interest.
Write a C# program for random number.
Find out factorial of any number using C# program.
Access file name & file size using C# program
Program to display drive information using C#
Program to implement user defined Exception using C#
Write a program for finally block using C#
Write a C# program for Any five string functions
Write a C# program for date time object
Simple program to display Welcome on ASP.NET Website
Program to implement Control transfer Controls
Program to implement CheckBox Control: Bold, Italic, Underline
Program to implement Dropdown list controls
Program to implement all validation Controls
Program to perform add, modify and delete operation on Database.
Program to implement Radio button Controls for font size.
Write a JSP program using math. random function
Program to convert temperature from Celsius to Fahrenheit using JSP
Write a C# program to calculate area of circle.
Write a C# program to calculate area of rectangle.
Write a C# program to check whether year is leap year or not.
Write a C# program to find out sum of even no. & sum of odd number.
Write a C# program to show multiple try catch box
Write a C# program for following string functions(lower,trim,length,indexof)
Write a C# program to accept file name & check whether it is exist or not
Create “D1/D2/D3” directories using C# program.
Program to implement Control transfer Controls( image button , link button)
Write a program to use adrotator control
Write a program to use calendar control
Program to implement validation Controls(Compare Validator,Range validator, Regular
expression validator)
count
------
<HTML>
<BODY>
<%! private static int count_access = 0; %>
This page has been accessed
<%= ++count_access %>
</BODY>
</HTML>
-------------------------------------------------------
page directive
--------
<%@ page language="java"
import="java.rmi.*,java.util.*"
session="true"
buffer="12kb"
autoFlush="true"
info="page directive jsp"
errorPage="Error.jsp"
isErrorPage="false"
isThreadSafe="false" %>
<html>
<head>
<title>Jsp Elements</title>
</head>
<body>
<h1> Jsp Elements</h1>
</body>
</html>
---------------------------------------------------------
forword-param
------
<html>
<body>
<jsp:forward page = "jspparam2.jsp">
<jsp:param name ="myparam" value="SAMEER" />
<jsp:param name ="age" value="23" />
</jsp:forward>
</body>
</html>
---------
<% String name1=request.getParameter("myparam"); %>
<% String age1=request.getParameter("age"); %>
<html>
<body>
Name=<%= name1 %>
Age=<%= age1 %>
</body>
</html>
---------
<html>
<body>
<% String name1 =request.getAttribute("myparam");
out.println(name1);
%>
<% String age1 =request.getAttribute("age");
out.println(age1);
%>
</body>
</html>
---------------------------------------------------------
convert temperature from Fahrenheit to Celsius
-------------------
<%@ page import="java.text.*" session="false" %>
<html><head><title>Scriptlet Example </title></head><body>
<table border="0" cellpadding="3">
<tr>
<th>Fahrenight</th>
<th>Celsius</th>
</tr>
<%
NumberFormat fmt = new DecimalFormat("###.000");
for(int f=32; f<=212; f+=20)
{
double c =((f-32)*5)/9.0;
String cs =fmt.format(c);
%>
<tr>
<td align ="right"><%=f%></td>
<td align ="right"><%=cs%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
--------------------------------------------------------
Your machines address
---------------------
<html>
<body>
<%
// This scriptlet declares & initialises "date"
System.out.println("Evaluating the Date now ");
java.util.Date date=new java.util.Date();
%>
Hello! The Time is now
<%
out.println("date");
out.println("<br>Your machines address is <br>");
out.println(request.getRemoteHost());
%>
</body>
</html>
------------------------------------------
using math. random function
---------------------------
<html>
<body>
<% out.println("Hello world!!"); %>
2+2 equals <%= 2+2 %>
<% if(Math.random()>0.5)
{ %>
Have a <b>happy</b> birthday!!!!
<% } else
{%>
Have a <b> nice </b> day!!!!
<%
} %></body></html>
-----------------------------------------
-----------------------------------------
servlet....
get method..
------------
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class Myget extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
System.out.println("Service Method") ;
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello</title>");
out.println("<body>");
out.println("<h1>Myget</h1>");
out.println("<body>");
out.println("<html>");
out.close();
}
}
---------------------------------------
post method
-------------
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class Mypost extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
String s1,s2;
s1=req.getParameter("uname");
s2=req.getParameter("pwd");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello</title>");
out.println("<body>");
out.println("Username : "+s1);
out.println("Password : "+s2);
out.println("</body>");
out.println("</html>");
out.close();
}
}
-------------------------------------------------
request method..
---------------
import java.io.* ;
import javax.servlet.*;
import javax.servlet.http.*;

public class Requestinfo extends HttpServlet


{
public void doGet(HttpServletRequest req , HttpServletResponse res)
throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out =res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>RequestInfo Example</title>");
out.println("</head>");
out.println("<h3>RequestInfoExample</h3>");
out.println("Method:"+ req.getMethod());
out.println("Request URL:"+ req.getRequestURI());
out.println("Protocol:"+ req.getProtocol());
out.println("PathInfo:"+ req.getRemoteAddr());
out.println("</body>");
out.println("</html>");
out.close();
}
}
--------------------------------------------------------
counter
----------
import javax.servlet.*;
import java.io.*;

public class counter extends GenericServlet


{
static int count ;
public void init(ServletConfig con)
{
count=0;
System.out.println("init method___");
}
public void service(ServletRequest req,ServletResponse res)throws
IOException,ServletException
{
System.out.println("ServiceMethod.....");
PrintWriter out=res.getWriter();
count++;
out.println("<html>");
out.println("<head>");
out.println("<title>Hello</title>");
out.println("<body>");
out.println("Your visitor no is :"+count);
out.println("</body>");
out.println("</html>");
out.close();
}
public void destroy()
{
System.out.println("Destroy Method");
}
}
---------------------------------------------------
session
----------
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.net.*;
import javax.servlet.util.*;
public class Showsession extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
res.setContentType("text/html") ;
PrintWriter out = res.getWriter();
HttpSession s1 = res.getSession(true);
String s1id = s1.getID();
out.println("<html>") ;
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Session</title>");
out.println("<body>");
out.println("Session ID : "+s1ID);
out.println("</body>");
out.println("</html>");
out.close();
}
}
-----------------------------------------------------
user password
----------------
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class passwdcheck extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
String s1,s2,s3,s4;
s3="sameer";
s4="parab";
s1=req.getParameter("uname");
s2=req.getParameter("pwd");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello</title>");
out.println("<body>");
out.println("Entered Data: ");
out.println("Username : "+s1);
out.println("Password : "+s2);
out.println("Matching Password and Username ");
if(s1.Equals(s3))
out.println("Username is Correct");
else
out.println("Username is incorret");
if(s2.Equals(s4))
out.println("Password is Correct");
else
out.println("Password is incorret");
out.println("</body>");
out.println("</html>");
out.close();
}
}
area of circle
----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Class3
{
static void Main()
{
Double r;
Double area;

Console.WriteLine("Enter radius:");
r = Convert.ToDouble(Console.ReadLine());
area = 3.14*r*r;
Console.WriteLine("Area of Circle:" +area);
Console.ReadLine();
}}}
Command line argument:
----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Class4
{
static void Main(String[] args)
{
Console.WriteLine("Hello,{0}",args[0]);
Console.WriteLine("Welcome to C#");
}}}
simple interest
-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Class5
{
static void Main()
{
Double P, r, n;
Double si;
Console.WriteLine("Enter Principle Amount");
P = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter number of years:");
n = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Rate");
r = Convert.ToDouble(Console.ReadLine());

si = P * n * r / 100;
Console.WriteLine("Simple Interest:" + si);
}}}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Class6
{
public static void Main()
{
Console.Write("What is your name?");
Console.Write("Hello, {0}!" , Console.ReadLine());
Console.WriteLine("Welcome to C#");
Console.ReadLine();
}}}
maths operation:
-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Class7
{
static void Main(string[]args)
{
Double a = -345.34, b = 23.87;
int i = 10, j = 20;
Console.WriteLine(Math.Abs(a));
Console.WriteLine(Math.Ceiling(b));
Console.WriteLine(Math.Floor(b));
Console.WriteLine(Math.Max(i, j));
Console.WriteLine(Math.Min(i, j));
Console.WriteLine(Math.Pow(2, 5));
Console.ReadLine();
}
}
}
area of rectangle
------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class rectangle
{
int height, width;
public void accept()
{
Console.WriteLine("Enter height and width");
height = Convert.ToInt32(Console.ReadLine());
width = Convert.ToInt32(Console.ReadLine());
}
public int area()
{
return height * width;
}
}
class Class8
{
static void Main()
{
rectangle r = new rectangle();
r.accept();
int a;
a = r.area();
Console.WriteLine("Area of rectangle:"+a);
}

}
}
Factorial of no.
-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Class9
{
static void Main()
{int n;
Console.WriteLine("Enter number");
n = Convert.ToInt32(Console.ReadLine());
int f = fact(n);
Console.WriteLine("Factorial:" + f);
}
static int fact(int n)
{
if (n > 1)
return n*fact(n - 1);
else
return 1;

}
}
}

Leap year
-----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int year;
Console.WriteLine("Enter the year Value :-");
year=Int32.Parse(Console.ReadLine());
if(year % 4 == 0 && year % 100 !=0) || year % 400 ==0 )
Console.WriteLine("The Year {0} is Leap year",year);
else
Console.WriteLine("The Year {0} is not Leap year",year);
Console.WriteLine("\n Press Enter to Quit......." );
Console.ReadLine();
}
}
}
jagged array
------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
public class Class1
{
public static void Main()
{
int[][] a = new int[3][];
a[0] = new int[2];
a[1] = new int[4];
a[2] = new int[3];
a[0][0] = 10; a[0][1] = 20;
a[1][0] = 30; a[1][1] = 40;
a[1][2] = 50; a[1][3] = 60;
a[2][0] = 70; a[2][1] = 80; a[2][2] = 90;
for (int i = 0; i <= a.GetUpperBound(0); i++)
{
for (int j = 0; j <= a[i].GetUpperBound(0); j++)
{
Console.Write(a[i][j] + " ");
}
Console.WriteLine();
}
}
}

}
drive information:
--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
foreach (DriveInfo d in DriveInfo.GetDrives())
{
try
{
Console.WriteLine(d.Name + " " + d.VolumeLabel + " " + d.TotalFreeSpace + " "
+ d.TotalSize);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.Read();
}
}} }
finally
----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sam_Console_App
{
class Class6
{
public static void Main()
{
int[] a = { 10, 20, 30, 40, 50, 60 };
int n;
try
{
Console.WriteLine("Enter Index Number");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Value " + a[n]);
}

catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.WriteLine("Program End........");
}}}}

try catch
----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
class myexception : Exception
{
public myexception(string msg)
: base(msg)
{}
}

class Program
{
static void Main(string[] args)
{

int bal;
try
{
Console.WriteLine("Enter balance");
bal = Convert.ToInt32(Console.ReadLine());
if (bal < 500)
throw new myexception("Balanace is less");
Console.WriteLine("Balance is "+bal);
}
catch(myexception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}}}
user defined exception:
-------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
class myexception : Exception
{
public myexception(string msg)
: base(msg)
{}
}

class Program
{
static void Main(string[] args)
{
int bal;
try
{
Console.WriteLine("Enter balance");
bal = Convert.ToInt32(Console.ReadLine());

if (bal < 500)


throw new myexception("Balanace is less");
Console.WriteLine("Balance is "+bal);

}
catch(myexception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
} }}
create a file:
--------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
StreamWriter sw = null;
String data;
try
{
sw = new StreamWriter("c:\\b.txt");
Console.WriteLine("Enter data");
data = Console.ReadLine();
sw.WriteLine(data);
Console.WriteLine("File created");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
if (sw != null)
sw.Close();
}
Console.Read();
} }}

Random number
---------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Console.WriteLine(r.Next(10));
Console.WriteLine(r.Next(10,100));
Console.ReadLine();

}}}
5 string functions
------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14
{
class Class1
{
static void Main(string[] args)
{
String s = " Hello ";
Console.WriteLine("Length:"+s.Length);
Console.WriteLine("Uppercase:"+s.ToUpper());
Console.WriteLine("Lowercase:"+s.ToLower());
Console.WriteLine("String:"+s.Trim());
String s1 = "Hello";
Console.WriteLine("Substring :"+s1.Substring(1));
Console.WriteLine("Substring :" + s1.Substring(1,3));
String s2 = "hello";
if (s1.Equals(s2))
{
Console.WriteLine("Equals");
}
else
{
Console.WriteLine("Not Equals");
}
Console.WriteLine("Replace : "+s2.Replace("e","i"));
String s3 = "This is a line of Text ";
Console.WriteLine("Index of : " + s3.IndexOf("is"));
Console.Read();
}}}

existence of file:
------------------
name and size of file:
------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication14
{
class Class2
{
static void Main(string[] args)
{
String fname;
Console.WriteLine("Enter the File Name :");
fname = Console.ReadLine();
FileInfo f = new FileInfo(fname);
if (f.Exists)
{
Console.WriteLine(" Name :" + f.FullName);
Console.WriteLine("Size:" + f.Length);
}
else
{
Console.WriteLine("File does not Exists ");
}
Console.Read();

}}}
Directory
-------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication14
{ class Class3
{

static void Main(string[] args)


{
Directory.CreateDirectory("d1");
Directory.CreateDirectory("d2/d3/d4");
Console.WriteLine(" Directory Created ");
Console.Read();
}}}

date time object


-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14
{
class Class4
{
static void Main(string[] args)
{
DateTime dt = new DateTime();
Console.WriteLine(dt.ToString());
dt=dt.AddDays(10);
Console.WriteLine(dt.ToString());
Console.WriteLine(dt.Day+"-"+dt.Month+"-"+dt.Year);
Console.Read() ;
}}}

sum of even and odd numbers


----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14
{
class Class5
{

static void Main(string[] args)


{
int i;
int Sum1=0, Sum2=0;
int[]a =new int[10] ;
for (i = 0; i < 10; i++ )
{
a[i] = Convert.ToInt32(Console.ReadLine());
}

for (i = 0; i < 10; i++)


{
if (a[i] % 2 == 0)
{
Sum1 = Sum1 + a[i];
}
else
{
Sum2 = Sum2 + a[i];
}
}
Console.WriteLine("Eum of Even Numbers:"+Sum1);
Console.WriteLine("Eum of odd Numbers:" + Sum2);
Console.Read();
}}}
welcome on 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)
{
Response.Write("<h1>Welcome to ASP.net</h1>");
Response.Write(" ");
}
}
Radiobutton controls for font size:
-----------------------------------
using System;
using System.Collections;
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 Default6 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
Label1.Font.Size = 10;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
Label1.Font.Size = 20;
}

protected void RadioButton3_CheckedChanged(object sender, EventArgs e)


{
Label1.Font.Size = 30;
}
}
control transfer controls
---------------------------
link button image button
-------------------------
using System;
using System.Collections;
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 Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("HTMLPage.htm");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default3.aspx");
}
protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
{
Response.Redirect("Default.aspx");
}
}
checkbox control
-----------------
using System;
using System.Collections;
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 Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
Label1.Font.Bold = true;
}
else
{
Label1.Font.Bold = false;
}

}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked == true)
{
Label1.Font.Italic = true;
}
else
{
Label1.Font.Italic = false;
}
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox3.Checked == true)
{
Label1.Font.Underline = true;
}
else
{
Label1.Font.Underline = false;
}
}
}
Dropdown list
--------------
using System;
using System.Collections;
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 Default8 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedValue;
}
}
adrotator control
------------------
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>
D:\Documents and Settings\Sameer\My Documents\My Pictures\the_fallen_-_wallpaper
</ImageUrl>
<NavigateUrl>Default.aspx</NavigateUrl>
<AlternateText>Flower</AlternateText>
<Keyword>a</Keyword>
<Impression>100</Impression>
</Ad>
<Ad>
<ImageUrl>
C:\nature_zh2urmp4.jpg
</ImageUrl>
<NavigateUrl>HTMLPage.htm</NavigateUrl>
<AlternateText>Nature</AlternateText>
<Keyword>b</Keyword>
<Impression>300</Impression>
</Ad>
<Ad>
<ImageUrl>C:\Winter.jpg</ImageUrl>
<NavigateUrl>Default3.aspx</NavigateUrl>
<AlternateText>winter</AlternateText>
<Keyword>c</Keyword>
<Impression>200</Impression>
</Ad>
<Ad>
<ImageUrl>C:\Sunset.jpg</ImageUrl>
<NavigateUrl>Default5.aspx</NavigateUrl>
<AlternateText>Sunset</AlternateText>
<Keyword>d</Keyword>
<Impression>400</Impression>
</Ad>
</Advertisements>

All validation controls:


-------------------------
using System;
using System.Collections;
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 Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs
args)
{
string s = args.Value;
if (s.Equals("M1") || s.Equals("M2") || s.Equals("M3"))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}

}
}
add modify and delete DATABASE
-------------------------------
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;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new OleDbConnection
("provider=microsoft.jet.oledb.4.0;data source=d:\\smita\\db1.mdb");
protected void Page_Load(object sender, EventArgs e)
{
display();
}
void display()
{
OleDbDataAdapter da = new OleDbDataAdapter("select * from emp", con);
DataSet ds = new DataSet();
da.Fill(ds, "emp");
GridView1.DataSource = ds.Tables["emp"].DefaultView;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string s;
s = string.Format("insert into emp values ({0},'{1}',{2},{3})", txteno.Text,
txtename.Text, txtsal.Text, txtdeptno.Text);
try
{
OleDbCommand cmd = new OleDbCommand(s, con);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record inserted";
}
catch (Exception ex)
{
Label1.Text = "Insertion failed!!";
}
finally
{
con.Close();
display();
}
}
protected void Button2_Click(object sender, EventArgs e)
{

string s;
s = string.Format("update emp set ename='{0}',sal={1},deptno={2} where eno={3}",
txtename.Text, txtsal.Text, txtdeptno.Text, txteno.Text);
try
{
OleDbCommand cmd = new OleDbCommand(s, con);
con.Open();
if (cmd.ExecuteNonQuery() == 1)
Label1.Text = "Record updated";
else
Label1.Text = "Empno does not exist";
display();
}
catch (Exception ex)
{
Label1.Text = "Updation failed!!";
}
finally
{
con.Close();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string s;
s = "delete from emp where eno=" + txteno.Text;
try
{
OleDbCommand cmd = new OleDbCommand(s, con);
con.Open();
if (cmd.ExecuteNonQuery() == 1)
Label1.Text = "Record deleted";
else
Label1.Text = "Empno does not exist";
display();
}
catch (Exception ex)
{
Label1.Text = "deletion failed";
}
finally
{
con.Close();
}}}
calender control:
----------------
public partial class Default10 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToString();
}
}

Das könnte Ihnen auch gefallen