Date post: | 09-Apr-2018 |
Category: |
Documents |
Upload: | honest-ragavan |
View: | 223 times |
Download: | 0 times |
of 74
8/8/2019 ASP Dot Net Full
1/74
www.Hiloo .com
like u tube
8/8/2019 ASP Dot Net Full
2/74
Response.Write(" Subtraction " + d +
"");
Response.Write("");%>
First No
Second No Addition
Subtraction
b && a > c)
Response.Write("A is Greatest");else
if (b > c)
Response.Write("B is Greatest");else
Response.Write("C is Greatest");
%>
b && a > c)
%>
A is Greatest
2
8/8/2019 ASP Dot Net Full
3/74
c)%>
B is Greatest
C is Greatest
http://localhost:1032/WebSite5?
CustomerNo=1001&CustomerName=M+Nagendhiran&Address=Fort+Main+Road&City=Namakkal&Pincode=637001
Korex.html
Customer No
Customer Name
Address
City Pincode
Default.aspx
8/8/2019 ASP Dot Net Full
4/74
%>
Korex.html
Customer No Customer Name
Address City
Pincode
Default.aspx
Korex.html
Customer No Customer Name
Address City
Pincode
4
8/8/2019 ASP Dot Net Full
5/74
Default.aspx
protected void lnkButton_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");}
5
8/8/2019 ASP Dot Net Full
6/74
8/8/2019 ASP Dot Net Full
7/74
for (int i = 0; i < lstSubject.Items.Count; ++i)
Response.Write(lstSubject.Items[i].Text + "
");
lstSubject.Items.RemoveAt(lstSubject.SelectedIndex);}
Arts
Science
Maths
B.Sc.,B.Com.,
protected void btnView_Click(object sender, EventArgs e)
{
for (int i = 0; i < chkList.Items.Count;
++i)Response.Write(chkList.Items[i].Text + "
");
for (int i = 0; i < chkList.Items.Count; ++i)
if(chkList.Items[i].Selected==true)Response.Write(chkList.Items[i].Text
+ "
");
for (int i = 0; i < chkList.Items.Count; ++i)
if (chkList.Items[i].Selected == true)chkList.Items.RemoveAt(i);
}
protected void chk_CheckedChanged(object sender, EventArgs e)
{
if (chk.Checked == true)chk.Text = "Male";
else
chk.Text = "FeMale";}
----------------------------------
7
8/8/2019 ASP Dot Net Full
8/74
protected void Red_CheckedChanged(object sender, EventArgs e){
lblMessage.BackColor = System.Drawing.Color.Red;
}protected void Green_CheckedChanged(object sender, EventArgs e)
{
lblMessage.BackColor = System.Drawing.Color.Green;
}protected void Blue_CheckedChanged(object sender, EventArgs e)
{
lblMessage.BackColor = System.Drawing.Color.Blue;
}
Red
GreenBlue
protected void Col_SelectedIndexChanged(object sender, EventArgs e)
{
if (Col.Text == "Red")lblMessage.BackColor = System.Drawing.Color.Red;
if (Col.Text == "Green")
lblMessage.BackColor = System.Drawing.Color.Green;if (Col.Text == "Blue")
lblMessage.BackColor = System.Drawing.Color.Blue;
}
1001501 Soap
8
8/8/2019 ASP Dot Net Full
9/74
1002
Lux Soap
protected void btnView_Click(object sender, EventArgs e){
R1.BackColor = System.Drawing.Color.Blue;
R2C2.Text = "Ponds Powder";
R2C2.BackColor = System.Drawing.Color.BurlyWood;}
Java
.NET
Visual BasicPHP
Name :
Address :
City :
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
9
8/8/2019 ASP Dot Net Full
10/74
}
Validation
10
8/8/2019 ASP Dot Net Full
11/74
Default.aspxpublic partial class _Default : System.Web.UI.Page
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";System.Data.SqlClient.SqlConnection Con = null;
protected void Page_Load(object sender, EventArgs e)
{Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = newSystem.Data.SqlClient.SqlDataAdapter("Select * from Customers", Con);
DataTable dt1 = new DataTable();adapter1.Fill(dt1);Response.Write("");
Response.Write(" Customer ID Company Name
Address City Country ");
foreach (DataRow row in dt1.Rows){
Response.Write(" " + row["CustomerID"] + "");
Response.Write("" + row["CompanyName"] + "");Response.Write("" + row["Address"] + "");
Response.Write("" + row["City"] + "");
Response.Write("" + row["Country"] + "");}
Response.Write("");
}}
-----------------------------
Korex.html
Country :
11
8/8/2019 ASP Dot Net Full
12/74
Default.aspx.cspublic partial class _Default : System.Web.UI.Page
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";System.Data.SqlClient.SqlConnection Con = null;
protected void Page_Load(object sender, EventArgs e)
{
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select * from Customers where Country='" +
Request.QueryString["Country"] + "'", Con);DataTable dt1 = new DataTable();
adapter1.Fill(dt1);Response.Write("");
Response.Write(" Customer ID Company Name
Address City Country ");
foreach (DataRow row in dt1.Rows){
Response.Write(" " + row["CustomerID"] + "");
Response.Write("" + row["CompanyName"] + "");Response.Write("" + row["Address"] + "");
Response.Write("" + row["City"] + "");
Response.Write("" + row["Country"] + "");}
Response.Write("");
}}
Default2.aspx.cs
public partial class Default2 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select distinct(Country) from Customers",
Con);
12
8/8/2019 ASP Dot Net Full
13/74
DataTable dt1 = new DataTable();
adapter1.Fill(dt1);
Response.Write("");Response.Write("Country : ");
foreach (DataRow row in dt1.Rows)
Response.Write("" + row["Country"] + "");Response.Write("");
Response.Write("");
}}
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;protected void Page_Load(object sender, EventArgs e)
{Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select * from Customers where Country='" +Request.QueryString["Country"] + "'", Con);
DataTable dt1 = new DataTable();
adapter1.Fill(dt1);Response.Write(" Country : " +
Request.QueryString["Country"]);
Response.Write("");Response.Write(" Customer ID Company Name
Address City ");
foreach (DataRow row in dt1.Rows){
Response.Write(" " + row["CustomerID"] + "");
Response.Write("" + row["CompanyName"] + "");
Response.Write("" + row["Address"] + "");Response.Write("" + row["City"] + "");
}
Response.Write("");}
}
----------------------------------
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
13
8/8/2019 ASP Dot Net Full
14/74
System.Data.SqlClient.SqlConnection Con = null;
protected void Page_Load(object sender, EventArgs e)
{Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = newSystem.Data.SqlClient.SqlDataAdapter("Select * from Customers", Con);
DataTable dt1 = new DataTable();
adapter1.Fill(dt1);Response.Write("");
Response.Write(" Customer ID Company Name
Address City Country");
foreach (DataRow row in dt1.Rows){
Response.Write(" "+row["CustomerID"] + "");
Response.Write("" + row["CompanyName"] + "");Response.Write("" + row["Address"] + "");
Response.Write("" + row["City"] + "");Response.Write("" + row["Country"] + "");
}
Response.Write("");
}}
Default2.aspx.cs
public partial class Default2 : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";System.Data.SqlClient.SqlConnection Con = null;
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select * from Orders where CUstomerID='" +
Request.QueryString["CustomerID"] + "'", Con);
DataTable dt1 = new DataTable();adapter1.Fill(dt1);
Response.Write("");
Response.Write(" Order ID Order Date Customer ID Employee ID ");
foreach (DataRow row in dt1.Rows)
{Response.Write(" " + row["OrderID"] + "");
Response.Write("" + row["OrderDate"] + "");
Response.Write("" + row["CustomerID"] + "");
Response.Write("" + row["EMployeeID"] + "");
14
8/8/2019 ASP Dot Net Full
15/74
}
Response.Write("");
}}
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";System.Data.SqlClient.SqlConnection Con = null;
protected void Page_Load(object sender, EventArgs e)
{Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select * from Customers", Con);DataTable dt1 = new DataTable();
adapter1.Fill(dt1);
Response.Write("");Response.Write(" Customer ID Company Name
Address City Country");
foreach (DataRow row in dt1.Rows){
Response.Write(" "+row["CustomerID"] + "");Response.Write("" + row["CompanyName"] + "");
Response.Write("" + row["Address"] + "");Response.Write("" + row["City"] + "");Response.Write("" + row["Country"] + "");
}
Response.Write("");
}}
Default2.aspx
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);Con.Open();
string sq = "select o.orderid,o.orderdate,o.customerid,c.companyname,"
+ "c.address,c.city,o.employeeid,e.firstname "
15
8/8/2019 ASP Dot Net Full
16/74
+ " from Customers c,Employees e,Orders o where o.CustomerID = c.CustomerID and "
+ " o.Employeeid = e.employeeid and o.Customerid='" +
Request.QueryString["CustomerID"] + "'";System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter(sq, Con);
DataTable dt1 = new DataTable();adapter1.Fill(dt1);
Response.Write("");
Response.Write(" Order ID Order Date Customer Address Employee Address ");
foreach (DataRow row in dt1.Rows)
{
Response.Write(" " + row["OrderID"] + "");Response.Write("" + row["OrderDate"] + "");
Response.Write("" + row["CustomerID"] + "
");
Response.Write(row["CompanyName"] + "
" + row["Address"] + "
" +
row["City"] + "");Response.Write("" + row["EMployeeID"] +
"
" + row["FirstName"] +
"");}
Response.Write("");
}
}
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;protected void Page_Load(object sender, EventArgs e){
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = newSystem.Data.SqlClient.SqlDataAdapter("Select * from Customers", Con);
DataTable dt1 = new DataTable();
adapter1.Fill(dt1);Response.Write("");
Response.Write(" Customer ID Company Name
Address City Country");foreach (DataRow row in dt1.Rows)
{
Response.Write(" "+row["CustomerID"] + "");Response.Write("" + row["CompanyName"] + "");
Response.Write("" + row["Address"] + "");
Response.Write("" + row["City"] + "");
16
8/8/2019 ASP Dot Net Full
17/74
Response.Write("" + row["Country"] + "");
}
Response.Write("");}}
Default2.aspx.cs
public partial class Default2 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();string sq = "select o.orderid,o.orderdate,o.customerid,c.companyname,"
+ "c.address,c.city,o.employeeid,e.firstname "
+ " from Customers c,Employees e,Orders o where o.CustomerID = c.CustomerID and "
+ " o.Employeeid = e.employeeid and o.Customerid='" +Request.QueryString["CustomerID"] + "'";
System.Data.SqlClient.SqlDataAdapter adapter1 = newSystem.Data.SqlClient.SqlDataAdapter(sq, Con);
DataTable dt1 = new DataTable();
adapter1.Fill(dt1);
int x = 0;foreach (DataRow row in dt1.Rows)
{
if (x == 0){
Response.Write("");
Response.Write("");Response.Write(" Customer ID " + row["CustomerID"] +
"");
Response.Write(" Company Name " + row["CompanyName"] +"");
Response.Write(" Address " + row["Address"] + "");
Response.Write(" City " + row["City"] + "");
Response.Write("");Response.Write("");
Response.Write(" Order ID Order Date
Employee ID First Name ");x = 1;
}
Response.Write(" " + row["OrderID"] + "");Response.Write("" + row["OrderDate"] + "");
Response.Write("" + row["EMployeeID"] + "" + row["FirstName"] +
"");
}Response.Write("");
17
8/8/2019 ASP Dot Net Full
18/74
}}
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;protected void Page_Load(object sender, EventArgs e)
{
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);Con.Open();
System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select * from Orders", Con);
DataTable dt1 = new DataTable();adapter1.Fill(dt1);
Response.Write("");
Response.Write(" Order ID Order DAte Customer ID Employee ID");
foreach (DataRow row in dt1.Rows)
{Response.Write(" "+row["OrderID"]+"");
Response.Write("" + row["OrderDate"] + "");Response.Write("" + row["CustomerID"] + "");
Response.Write("" + row["EmployeeID"] + "");}Response.Write("");
}
}
Default2.aspx.cs
public partial class Default2 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{string ConnectionString = "server=localhost;user id=sa;initial catalog=NorthWind";
System.Data.SqlClient.SqlConnection Con = null;
Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();string sq = "select o.orderid,o.orderdate,o.customerid,c.companyname,"
+ "c.address,c.city,o.employeeid, e.firstname,od.productid,p.productname,od.unitprice,
od.quantity, od.unitprice * od.quantity as Total "
18
8/8/2019 ASP Dot Net Full
19/74
+ " from Customers c,Employees e,Orders o,[Order Details] od,Products p where
o.CustomerID = c.CustomerID and "
+ " o.Employeeid = e.employeeid and o.orderid=od.orderid and od.productid=p.productidand o.orderid=" + Request.QueryString["OrderID"];
System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter(sq, Con);DataTable dt1 = new DataTable();
adapter1.Fill(dt1);
int x = 0,sno=1;float tot = 0.0f;
foreach (DataRow row in dt1.Rows)
{
if (x == 0){
Response.Write("");
Response.Write("");
Response.Write(" Order ID " + row["OrderID"] + "");Response.Write("Order Date " + row["OrderDate"] + "");
Response.Write(" Customer ID " + row["CustomerID"] + "");Response.Write(" Company Name " + row["CompanyName"] +
"");
Response.Write(" Address " + row["Address"] + "");
Response.Write(" City " + row["City"] + "");Response.Write(" Employee ID " + row["EmployeeID"] + "");
Response.Write(" First Name " + row["FirstName"] + "");
Response.Write("");Response.Write("");
Response.Write(" Sno Product ID
Product Name Unit Price Quantity Total ");x = 1;
}
Response.Write(" " + sno + "");Response.Write("" + row["ProductID"] + "");
Response.Write("" + row["ProductName"] + "");
Response.Write("" + row["UnitPrice"] + "");
Response.Write("" + row["Quantity"] + "");Response.Write("" + row["Total"] + "");
tot += float.Parse(row["Total"].ToString());
sno++;}
Response.Write(" Total" +
tot + "");Response.Write("");
}
}
19
8/8/2019 ASP Dot Net Full
20/74
Java Script
Untitled Page
function View()
{alert("Hello");
}
Untitled Page
Untitled Page
function View()
{User=document.form1.UserName.value;
if(User.length==0)
{
alert("Please Type the User Name");return false;
}
for(i=0;i
8/8/2019 ASP Dot Net Full
21/74
{
if( (User.charAt(i)>='A' && User.charAt(i)='a' &&
User.charAt(i)
8/8/2019 ASP Dot Net Full
22/74
}
for(i=0;i='A' && Last.charAt(i)='a' &&
Last.charAt(i)
8/8/2019 ASP Dot Net Full
23/74
Korex.js
function CharacterOnly(st,st1)
{if(st.length==0)
{
alert("Please Type the "+st1);
return false;}
for(i=0;i='A' && st.charAt(i)='a' && st.charAt(i)
8/8/2019 ASP Dot Net Full
24/74
Default.aspx
Untitled Page
function View(){
if( CharacterOnly(document.EMail.UserName.value,"User Name")==false) return false;
if( CharacterOnly(document.EMail.FirstName.value,"First Name")==false) return false;
if( CharacterOnly(document.EMail.LastName.value,"Last Name")==false) return false;if( NumericOnly(document.EMail.Amount.value,"Amount")==false) return false;
alert("Valid Data");
return true;
}
User Name
Pass Word Retype PassWord
First Name Last Name
Amount
24
8/8/2019 ASP Dot Net Full
25/74
Style Sheet (.CSS ->Cascading Style Sheet)
Internal Style Sheet
Untitled Page
H1
{
Font-Family:Arial Black;
}.H1Class
{
Color:Red;
}
Welcome to Korex
Fort Main Road
Namakkal
External Style Sheet
Korex.css
H1
{Font-Family:Arial Black;
}
.H1Class
{Color:Red;
}
P{
border-bottom-width:thick;
border-bottom-color:Maroon;border-bottom-style:groove;
}
25
8/8/2019 ASP Dot Net Full
26/74
.PClass
{background-color:Green;
text-align:justify;
}
Default.aspx
Untitled Page
Welcome to Korex
Fort Main Road
Namakkal
With WordPad, you can create and edit simple text documents or documents withcomplex formatting and graphics. You can information from other documents into a
WordPad document.You can save your WordPad file as a text file, rich text file, text file
for MS-DOS These formats provide greater flexibility when working with otherprograms. Documents that use multiple languages should be saved as rich text files.
With WordPad, you can create and edit simple text documents or documents with
complex formatting and graphics. You can information from other documents into aWordPad document.You can save your WordPad file as a text file, rich text file, text filefor MS-DOS These formats provide greater flexibility when working with other
programs. Documents that use multiple languages should be saved as rich text files.
Next
//Hidden Variable
1.html
User Name
Pass Word
26
8/8/2019 ASP Dot Net Full
27/74
Default.aspx
Default2.aspx
Product No
Product Name
Unit Price Quantity
27
8/8/2019 ASP Dot Net Full
28/74
Default3.aspx
User Name
Pass Word Product No
Product Name
Unit Price
Quantity
Session Variable
1.html
User Name
Pass Word
Default.aspx
8/8/2019 ASP Dot Net Full
29/74
Session["PassWord"] = PassWord;
Response.Redirect("Default2.aspx");
}else
{
Response.Write("The User Name and PassWord is Not Correct");Response.Write("");
Response.Write("");
Response.Write("");}
%>
Default2.aspx
Product No
Product Name Unit Price
Quantity
Default3.aspx
User Name
Pass Word
Product No Product Name
Unit Price
Quantity
29
8/8/2019 ASP Dot Net Full
30/74
Cookies
1.html
User Name
Pass Word
Default.aspx
30
8/8/2019 ASP Dot Net Full
31/74
Default2.aspx
Product No
Product Name
Unit Price Quantity
Default3.aspx
User Name Pass Word
Product No
Product Name Unit Price
Quantity
void Application_Start(object sender, EventArgs e)
{
Application["Count"] = 0;}
31
8/8/2019 ASP Dot Net Full
32/74
void Application_End(object sender, EventArgs e)
{// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e){
// Code that runs when an unhandled error occurs
}void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}protected void Application_BeginRequest(object sender, EventArgs e)
{
Application.Lock();
int co = (int)Application["Count"];co++;
Application["Count"] = co;Application.UnLock();
}
The Number of Time Count : The Number of Time Count :
Web Service
[WebMethod]
public string HelloWorld()
{return "Hello World";
}
[WebMethod]
public int Sum(int a, int b){
return a + b;
}
32
8/8/2019 ASP Dot Net Full
33/74
protected void btnView_Click(object sender, EventArgs e)
{int a, b, c;
a = 10;
b = 3;Korex.Service Kct = new Korex.Service();
c = Kct.Sum(a, b);
Response.Write("Addition : " + c);string s = Kct.HelloWorld();
Response.Write(s);
}
Layer Concept
DataBaseLayer.cs
public class DataBaseLayer
{
System.Data.SqlClient.SqlConnection Con = null;private string ConnectionString = "server=localhost;user id=sa;initial catalog=master";
public DataBaseLayer()
{Con = new System.Data.SqlClient.SqlConnection(ConnectionString);
Con.Open();
}public System.Data.DataSet ViewRecord()
{DataSet ds = new DataSet();System.Data.SqlClient.SqlDataAdapter adapter1 = new
System.Data.SqlClient.SqlDataAdapter("Select * from CustomerDetails", Con);
adapter1.Fill(ds, "Customer");
adapter1.Dispose();adapter1 = new System.Data.SqlClient.SqlDataAdapter("Select * from ProductDetails",
Con);
adapter1.Fill(ds, "Product");return ds;
}
public object SaveRecord(object obj, string st)
{
try
{string sq = "";
if (st.Equals("Customer"))
{
33
8/8/2019 ASP Dot Net Full
34/74
UICustomerDetails Cust = (UICustomerDetails)obj;
sq = "insert into CustomerDetails(CustomerNo,CustomerName,"
+ "Address,City,Pincode) values(" + Cust.CustomerNo + ",'"+ Cust.CustomerName + "','" + Cust.Address + "','" + Cust.City + "'," + Cust.Pincode +
")";
}if (st.Equals("Product"))
{
UIProductDetails Prod = (UIProductDetails)obj;sq = "insert into ProductDetails(ProductNo,ProductName,UnitPrice) values("
+ Prod.ProductNo + ",'" + Prod.ProductName + "'," + Prod.UnitPrice + ")";
}
System.Data.SqlClient.SqlCommand cmd = newSystem.Data.SqlClient.SqlCommand(sq, Con);
cmd.ExecuteNonQuery();
return (object)"The Record is Saved";
}catch (Exception e1)
{return (object)e1.Message;
}
}
}
BusinessLogicLayer.cs
public class BusinessLogicLayer{
DataBaseLayer Data = new DataBaseLayer();
DataSet ds = new DataSet();public BusinessLogicLayer()
{
ds = Data.ViewRecord();}
public object SaveRecord(object obj, string st)
{
return Data.SaveRecord(obj,st);}
public DataRow[] ViewRecord(string con, string st){
DataRow[] row = ds.Tables[st].Select(con);
return row;}
}
34
8/8/2019 ASP Dot Net Full
35/74
UICustomerDetails.aspx
public class UICustomerDetails
{
private int mvarCustomerNo;private string mvarCustomerName, mvarAddress, mvarCity;
private long mvarPincode;
public int CustomerNo{
set { mvarCustomerNo = value; }
get { return mvarCustomerNo; }
}public string CustomerName
{
set { mvarCustomerName = value; }
get { return mvarCustomerName; }}
public string Address{
set { mvarAddress = value; }
get { return mvarAddress; }
}public string City
{
set { mvarCity = value; }get { return mvarCity; }
}
public long Pincode{
set { mvarPincode = value; }
get { return mvarPincode; }}
}
UIProductDetails.aspx
public class UIProductDetails
{private int mvarProductNo;
private string mvarProductName;
private float mvarUnitPrice;public int ProductNo
{
set { mvarProductNo = value; }
get { return mvarProductNo; }
35
8/8/2019 ASP Dot Net Full
36/74
}
public string ProductName
{set { mvarProductName = value; }
get { return mvarProductName; }
}public float UnitPrice
{
set { mvarUnitPrice = value; }get { return mvarUnitPrice; }
}
}
PresentationLayer
CustomerDetails.aspx
Customer No Customer Name
Address
City Pincode
36
8/8/2019 ASP Dot Net Full
37/74
CustomerDetails.aspx.cs
public partial class CustomerDetails : System.Web.UI.Page
{
BusinessLogicLayer Bus = new BusinessLogicLayer();protected void btnSave_Click(object sender, EventArgs e)
{
UICustomerDetails Cust = new UICustomerDetails();Cust.CustomerNo = int.Parse(txtCustomerNo.Text);
Cust.CustomerName = txtCustomerName.Text;
Cust.Address = txtAddress.Text;
Cust.City = txtCity.Text;Cust.Pincode = long.Parse(txtPincode.Text);
lblMessage.Text = (string)Bus.SaveRecord((object)Cust, "Customer");
}
protected void btnView_Click(object sender, EventArgs e){
DataRow[] row = Bus.ViewRecord("CustomerNo=" + txtCustomerNo.Text,"Customer");
if (row.Length == 0)
{
lblMessage.Text = "The Customer Number Does Not Exist";txtCustomerName.Text = "";
txtAddress.Text = "";
txtCity.Text = "";txtPincode.Text = "";
}
else{
txtCustomerName.Text = row[0]["CustomerName"].ToString();
txtAddress.Text = row[0]["Address"].ToString();txtCity.Text = row[0]["City"].ToString();
txtPincode.Text = row[0]["Pincode"].ToString();
}
}}
ProductDetails.aspx
Product No
37
8/8/2019 ASP Dot Net Full
38/74
Product Name
Unit Price
ProductDetails.aspx.cs
public partial class ProductDetails : System.Web.UI.Page
{
BusinessLogicLayer Bus = new BusinessLogicLayer();
protected void btnSave_Click(object sender, EventArgs e){
UIProductDetails Prod = new UIProductDetails();
Prod.ProductNo = int.Parse(txtProductNo.Text);Prod.ProductName = txtProductName.Text;
Prod.UnitPrice = float.Parse(txtUnitPrice.Text);
lblMessage.Text = (string)Bus.SaveRecord((object)Prod, "Product");}
protected void btnView_Click(object sender, EventArgs e)
{DataRow[] row = Bus.ViewRecord("ProductNo=" + txtProductNo.Text, "Product");
if (row.Length == 0)
{
lblMessage.Text = "The Product Number Does Not Exist";txtProductName.Text = "";
txtUnitPrice.Text = "";
}else
{
txtProductName.Text = row[0]["ProductName"].ToString();txtUnitPrice.Text = row[0]["UnitPrice"].ToString();
}
}
}
38
8/8/2019 ASP Dot Net Full
39/74
Default.aspx
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{protected void btnCustomer_Click(object sender, EventArgs e)
{Response.Redirect("CustomerDetails.aspx");
}
protected void btnProduct_Click(object sender, EventArgs e)
{Response.Redirect("ProductDetails.aspx");
}
}
Web User Control
Welcome to Korex Computer Technique
Namakkal
39
8/8/2019 ASP Dot Net Full
40/74
Welcome to Korex Computer Technique
Namakkal
public string a = "Korex Computer Technique ";
public string b = "Namakkal";
40
8/8/2019 ASP Dot Net Full
41/74
public int a = 0;
public void PrintLine(){
for (int i = 1; i
8/8/2019 ASP Dot Net Full
42/74
public int a = 0;
public void Display(){
for (int i = 1; i
8/8/2019 ASP Dot Net Full
43/74
First No Second No
Addition
Subtraction
XML
1001
M. Nagendhiran Fort Main Road
Namakkal
1002
Jayaraj
Bazzar Street Namakkal
1001
M. Nagendhiran
43
8/8/2019 ASP Dot Net Full
44/74
Fort Main Road
Namakkal
Tamil Nadu
Namakkal
1002Jayaraj
Bazzar Street
Namakkal Tamil Nadu
Namakkal
Student
Author Introduction to XML
Welcome to XML
var RootElement1;
//nodecount will store the number of nodes containing
//data in the XML file//dom [document object model]
var xmlDoc1 = new ActiveXObject("microsoft.xmldom");
xmlDoc1.load("Korex.xml");function StartUp()
{
if(xmlDoc1.readyState=="4")
{StartLoading();
}
else
44
8/8/2019 ASP Dot Net Full
45/74
{
alert("Proecess could not start");
}}
function StartLoading()
{ RootElement1 = xmlDoc1.documentElement;
todata.innerText=RootElement1.childNodes(0).text;
fromdata.innerText=RootElement1.childNodes(1).text;subjectdata.innerText=RootElement1.childNodes(2).text;
bodydata.innerText=RootElement1.childNodes(3).text;
}
To :
From :
Subject :
Body :
Korex1.xml
1001 Srini
400
Pass
Korex1.html
var RootElement1;
//nodecount will store the number of nodes containing
//data in the XML file
var xmlDoc1 = new ActiveXObject("microsoft.xmldom");var xmlDoc2 = new ActiveXObject("microsoft.xmldom");
xmlDoc1.load("Korex.xml");
xmlDoc2.load("Korex1.xml");
45
8/8/2019 ASP Dot Net Full
46/74
function StartUp()
{
if(xmlDoc1.readyState=="4" && xmlDoc2.readyState=="4"){
StartLoading();
}else
{
alert("Proecess count not start");}
}
function StartLoading()
{
RootElement1 = xmlDoc1.documentElement;
todata.innerText=RootElement1.childNodes(0).text;
fromdata.innerText=RootElement1.childNodes(1).text;subjectdata.innerText=RootElement1.childNodes(2).text;
bodydata.innerText=RootElement1.childNodes(3).text;
RootElement2 = xmlDoc2.documentElement;
rollno.innerText=RootElement2.childNodes(0).text;
name1.innerText=RootElement2.childNodes(1).text;marks.innerText=RootElement2.childNodes(2).text;
result.innerText=RootElement2.childNodes(3).text;
}
To :
From :
Subject :
Body :
Roll No:
Name :
Marks :
Result :
var RootElement1;//nodecount will store the number of nodes containing
//data in the XML file
var nodecount;
46
8/8/2019 ASP Dot Net Full
47/74
var xmlDoc1 = new ActiveXObject("microsoft.xmldom");
xmlDoc1.load("Korex.xml");
function StartUp(){
if(xmlDoc1.readyState=="4")
{ StartLoading();
}
else{
alert("Process count not start");
}
}function StartLoading()
{
RootElement1 = xmlDoc1.documentElement;nodecount=RootElement1.childNodes.length;
for(i=0;i
]>
&MYENTITYTO; Nagendhiran
&MYENTITYFROM; Computer Technique
&MYENTITYSUBJECT; Course
I am happy that you are reading my books
47
8/8/2019 ASP Dot Net Full
48/74
Ponds Powder
Lux Soap
VVD Oil
Fully Paided
]>
Ponds Powder Lux Soap
VVD Oil
Fully Paided
]>
Ponds Powder Lux Soap
VVD Oil
Fully Paided
Korex Bus Service
48
8/8/2019 ASP Dot Net Full
49/74
50 Person
Not Avaialble
Nagendhiran XML
1
120.45
0A
123
2004-01-03
Korex.XML
]>
&FIRST1;
&FIRST2;
&MYENTITYSUBJECT;
AJAX
Untitled Page
function HttpReq()
{alert("Hello");
}
49
8/8/2019 ASP Dot Net Full
50/74
XMLFile.xml
1001
M. Nagendhiran
Fort Main RoadNamakkal
Synchronous Requests
CommonAJAXLibrary.js
var XmlHttp;function CreateXmlHttp()
{
try{
XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){
try
{XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc){
XmlHttp = null;
}}
if(!XmlHttp && typeof XMLHttpRequest != "undefined")
{
XmlHttp = new XMLHttpRequest();}
}
50
8/8/2019 ASP Dot Net Full
51/74
Untitled Page
function HttpReq()
{
CreateXmlHttp();XmlHttp.open("GET","http://" + location.host +"/WebSite3/XMLFile.xml", false);
XmlHttp.send(null);
alert("Request/Response Complete.");
}
Asynchronous Requests
Untitled Page
function HttpReq()
{
var READYSTATE_UNINITIALIZED = 0;var READYSTATE_LOADING = 1;
var READYSTATE_LOADED = 2;
var READYSTATE_INTERACTIVE = 3;var READYSTATE_COMPLETE = 4;
CreateXmlHttp();
if (XmlHttp){
XmlHttp.open("GET","http://" + location.host +"/WebSite3/XMLFile.xml", true);
XmlHttp.onreadystatechange = function()
{alert(XmlHttp.readyState);
if ( XmlHttp.readyState == 4 )
{
51
8/8/2019 ASP Dot Net Full
52/74
alert("Request/Response Complete");
}
}XmlHttp.send(null);
}
}
Using the responseText Property
Untitled Page
function HttpReq(){
CreateXmlHttp();if (XmlHttp){
XmlHttp.open("GET","http://" + location.host +"/WebSite3/XMLFile.xml", true);
XmlHttp.onreadystatechange = function()
{if ( XmlHttp.readyState == 4 )
{
document.getElementById("Results").childNodes[0].nodeValue =XmlHttp.responseText;
}
}XmlHttp.send(null);
}
}
52
8/8/2019 ASP Dot Net Full
53/74
{no results}
Returning Response Data As an XML Document Object
Untitled Page
function HttpReq()
{ CreateXmlHttp();
if (XmlHttp)
{XmlHttp.open("GET","http://" + location.host +"/WebSite3/XMLFile.xml", true);
XmlHttp.onreadystatechange = function()
{if ( XmlHttp.readyState == 4 )
{
var doc = XmlHttp.responseXML;var node =
doc.selectSingleNode("//Korex/Customer/CustomerName/text()");document.getElementById("Results").childNodes[0].nodeValue =node.nodeValue;
}
}
XmlHttp.send(null);}
}
{no results}
53
8/8/2019 ASP Dot Net Full
54/74
Performing a Server Request Asynchronously
Untitled Page
function HttpReq(){
CreateXmlHttp();
if (XmlHttp)
{XmlHttp.open("GET","http://" + location.host +"/WebSite3/XMLFile.xml", true);
XmlHttp.send(null);
if (XmlHttp.status == 200)
{ var xmlDoc = XmlHttp.responseXML;
var nodes = xmlDoc.selectNodes("//Korex/Customer/CustomerName/text()");var ctrl = document.getElementById("ddlCustomers");
for (var i=0; i < nodes.length; i++)
{
var CustomerName = nodes[i].nodeValue;var htmlCode = document.createElement('option');
ctrl.options.add(htmlCode);
htmlCode.text = CustomerName;htmlCode.value = CustomerName;
}
}else
{
alert("There was a problem accessing the Customer data on the server.!");}
}
}
function DisplayCustomerDetails()
{
if (XmlHttp){
XmlHttp.open("GET","http://" + location.host +"/WebSite3/XMLFile.xml", true);
XmlHttp.send(null);if (XmlHttp.readyState == 4 )
{
var ctrl = document.getElementById("ddlCustomers");
var doc = XmlHttp.responseXML;
54
8/8/2019 ASP Dot Net Full
55/74
var CustomerName = ctrl.options[ctrl.selectedIndex].value;
var node = doc.selectSingleNode("//Korex/Customer[CustomerName='"
+CustomerName + "']");var Address = 'Address : '
+node.selectSingleNode('Address/text()').nodeValue
var City= 'City : '+node.selectSingleNode('City/text()').nodeValue;details=CustomerName+","+Address+","+City;
document.getElementById("spnDetailDisplay").childNodes[0].nodeValue=
details;}
}
}
- Select a Customer -
Details:
(You have not made a selection yet.)
Untitled Page
function HttpReq(){
CreateXmlHttp();
if (XmlHttp){
XmlHttp.open("GET","http://" + location.host +"/WebSite6/XMLFile.xml", true);
XmlHttp.send(null);
if (XmlHttp.status == 200){
var xmlDoc = XmlHttp.responseXML;
var nodes = xmlDoc.selectNodes("//Korex/Customer/CustomerName/text()");
55
8/8/2019 ASP Dot Net Full
56/74
var ctrl = document.getElementById("ddlCustomers");
for (var i=0; i < nodes.length; i++)
{var CustomerName = nodes[i].nodeValue;
var htmlCode = document.createElement('option');
ctrl.options.add(htmlCode);htmlCode.text = CustomerName;
htmlCode.value = CustomerName;
}}
else
{
alert("There was a problem accessing the Customer data on the server.!");}
}
}
function DisplayCustomerDetails()
{if (XmlHttp)
{
XmlHttp.open("GET","http://" + location.host +"/WebSite6/XMLFile.xml", true);
XmlHttp.send(null);if (XmlHttp.readyState == 4 )
{
var ctrl = document.getElementById("ddlCustomers");var doc = XmlHttp.responseXML;
var CustomerName = ctrl.options[ctrl.selectedIndex].value;
var node = doc.selectSingleNode("//Korex/Customer[CustomerName='"+CustomerName + "']");
var Address = node.selectSingleNode('Address/text()').nodeValue ;
var City= node.selectSingleNode('City/text()').nodeValue;document.getElementById("CustomerName").value=CustomerName;
document.getElementById("Address").value=Address;
document.getElementById("City").value=City;
}
}
}
- Select a Customer -
56
8/8/2019 ASP Dot Net Full
57/74
Details:
(You have not made a selection yet.)
Untitled Page
function HttpReq()
{
CreateXmlHttp();if (XmlHttp)
{
XmlHttp.open("GET","http://" + location.host +"/WebSite6/XMLFile.xml", true);XmlHttp.send(null);
if (XmlHttp.status == 200){var xmlDoc = XmlHttp.responseXML;
var nodes = xmlDoc.selectNodes("//Korex/Customer/CustomerName/text()");
var ctrl = document.getElementById("ddlCustomers");
for (var i=0; i < nodes.length; i++){
var CustomerName = nodes[i].nodeValue;
var htmlCode = document.createElement('option');ctrl.options.add(htmlCode);
htmlCode.text = CustomerName;
htmlCode.value = CustomerName;}
}
else
{alert("There was a problem accessing the Customer data on the server.!");
}
} }
57
8/8/2019 ASP Dot Net Full
58/74
function DisplayCustomerDetails()
{if (XmlHttp)
{
XmlHttp.open("GET","http://" + location.host +"/WebSite6/XMLFile.xml", true);XmlHttp.send(null);
if (XmlHttp.readyState == 4 )
{var ctrl = document.getElementById("ddlCustomers");
var doc = XmlHttp.responseXML;
var CustomerName = ctrl.options[ctrl.selectedIndex].value;
var node = doc.selectSingleNode("//Korex/Customer[CustomerName='"+CustomerName + "']");
var Address = node.selectSingleNode('Address/text()').nodeValue
var City= node.selectSingleNode('City/text()').nodeValue;
document.getElementById("CustomerName").value=CustomerName;document.getElementById("Address").value=Address;
document.getElementById("City").value=City;
}
}
}
- Select a Customer -
Details:
(You have not made a selection yet.)
58
8/8/2019 ASP Dot Net Full
59/74
Using a HTTP Handler
Untitled Page
function LoadCustomer()
{
CreateXmlHttp();
if (XmlHttp){
var ddlCtrl = document.getElementById("ddlCustomers");
var disp = document.getElementById("spnDetailDisplay");
var custNumber = ddlCtrl.value;XmlHttp.open("GET","http://" + location.host +"/WebSite3/Handler.ashx?
arg="+custNumber, true);XmlHttp.onreadystatechange = function()
{
if (XmlHttp.readyState == 4)
{if (XmlHttp.status == 200)
{
var xmlDoc = XmlHttp.responseXML;var name = xmlDoc.selectSingleNode("//root/Customer/name/text()");
var email = xmlDoc.selectSingleNode("//root/Customer/email/text()");
alert(name);disp.childNodes[0].nodeValue = "Name: " + name.nodeValue + "Email: "
+ email.nodeValue;
}}
}
XmlHttp.send("SomeDataToSend");
}}
- Select a Customer -
Customer 1
Customer 2
59
8/8/2019 ASP Dot Net Full
60/74
Customer 3
Details:
(You have not made a selection yet)Handler.ashx
using System;
using System.Web;
0public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context){
string param = context.Request.QueryString["arg"];
const string xmlData = @"{0}{1}";string returnXML = null;
switch (param)
{case "1":
returnXML = string.Format(xmlData, "Big Bob", "[email protected]");
break;case "2":
returnXML = string.Format(xmlData, "Small Sammy", "[email protected]");
break;case "3":
returnXML = string.Format(xmlData, "Large Larry", "[email protected]");
break;
}context.Response.ContentType = "application/xml";
context.Response.Write(returnXML);
}
public bool IsReusable {
get {return false;
}
}
}
60
8/8/2019 ASP Dot Net Full
61/74
//SQL-Server
use northwind
select * from Orders
select OrderID,OrderDate,CustomerID,EmployeeID from Orders
select * from Customers
select Orders.OrderID,Orders.OrderDate,Orders.CustomerID,
Customers.CompanyName,Customers.Address,Customers.City
from Orders,Customers
select Orders.OrderID,Orders.OrderDate,Orders.CustomerID,
Customers.CompanyName,Customers.Address,Customers.City
from Orders,Customers where Orders.CustomerID=Customers.CustomerID
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,c.Address,c.City
from Orders o,Customers c where o.CustomerID=c.CUstomerID
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,c.Address,c.City,o.EmployeeID,e.FirstName
from Orders o,Customers c,Employees e
where o.CustomerID=c.CUstomerID and o.EmployeeID = e.EmployeeID
Inner join
select Orders.OrderID,Orders.OrderDate,Orders.CustomerID,
Customers.CompanyName,Customers.Address,Customers.City
from Orders inner join Customers on orders.CustomerID=customers.CustomerID
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,
c.Address,c.City,o.EmployeeID,e.FirstName
from Orders o inner join Customers c on o.CustomerID=c.CustomerIDinner join Employees e on o.EmployeeID = e.EmployeeID
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,c.Address,c.City,o.EmployeeID,e.FirstName
from Orders o inner join Customers c on o.CustomerID=c.CustomerID
inner join Employees e on o.EmployeeID = e.EmployeeID whereo.OrderID between 10260 and 10360
61
8/8/2019 ASP Dot Net Full
62/74
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,
c.Address,c.City,o.EmployeeID,e.FirstName
from Orders o inner join Customers c on o.CustomerID=c.CustomerIDinner join Employees e on o.EmployeeID = e.EmployeeID where
o.OrderID between 10260 and 10360 and o.employeeid between 1 and 3
select * from [order details]
sp_columns Orders
select OrderID,ProductID,UnitPrice,Quantity,UnitPrice * Quantity as Total
from [Order Details]
select OrderID,ProductID,UnitPrice,Quantity,UnitPrice * Quantity as Total,
Discount,UnitPrice * Quantity * Discount as DiscountTotal,
(UnitPrice * Quantity) - (UnitPrice * Quantity * Discount)
as ProductValuefrom [Order Details]
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,
c.Address,c.City,o.EmployeeID,e.FirstName,e.LastName,
od.ProductID,p.ProductName,od.UnitPrice,od.Quantity,
od.Discount,(od.UnitPrice * od.Quantity) - (od.UnitPrice * od.Quantity *od.Discount) as Total,p.SupplierID,s.CompanyName as SupplierName,
p.CategoryID,Ca.CategoryName
from Orders o inner join Customers c on o.CustomerID=c.CustomerIDinner join Employees e on o.EmployeeID = e.EmployeeID inner join
[Order Details] od on o.OrderID=od.OrderiD inner join Products p
on od.ProductID=p.ProductID inner join Suppliers s onp.Supplierid=s.supplierid inner join Categories Ca on
p.Categoryid=Ca.CategoryID
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,
c.Address,c.City,o.EmployeeID,e.FirstName,e.LastName,
od.ProductID,p.ProductName,od.UnitPrice,od.Quantity,
od.Discount,(od.UnitPrice * od.Quantity) - (od.UnitPrice * od.Quantity *od.Discount) as Total,p.SupplierID,s.CompanyName as SupplierName,
p.CategoryID,Ca.CategoryName
from Orders o inner join Customers c on o.CustomerID=c.CustomerIDinner join Employees e on o.EmployeeID = e.EmployeeID inner join
[Order Details] od on o.OrderID=od.OrderiD inner join Products p
on od.ProductID=p.ProductID inner join Suppliers s onp.Supplierid=s.supplierid inner join Categories Ca on
p.Categoryid=Ca.CategoryID where o.orderid between 10260 and 10270
62
8/8/2019 ASP Dot Net Full
63/74
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,
c.Address,c.City,o.EmployeeID,e.FirstName,e.LastName,
od.ProductID,p.ProductName,od.UnitPrice,od.Quantity,od.Discount,(od.UnitPrice * od.Quantity) - (od.UnitPrice * od.Quantity *
od.Discount) as Total,p.SupplierID,s.CompanyName as SupplierName,
p.CategoryID,Ca.CategoryNamefrom Orders o inner join Customers c on o.CustomerID=c.CustomerID
inner join Employees e on o.EmployeeID = e.EmployeeID inner join
[Order Details] od on o.OrderID=od.OrderiD inner join Products pon od.ProductID=p.ProductID inner join Suppliers s on
p.Supplierid=s.supplierid inner join Categories Ca on
p.Categoryid=Ca.CategoryID where p.productname='Chai'
select o.OrderID,o.OrderDate,o.CustomerID,c.CompanyName,
c.Address,c.City,o.EmployeeID,e.FirstName,e.LastName,
od.ProductID,p.ProductName,od.UnitPrice,od.Quantity,od.Discount,(od.UnitPrice * od.Quantity) - (od.UnitPrice * od.Quantity *
od.Discount) as Total,p.SupplierID,s.CompanyName as SupplierName,p.CategoryID,Ca.CategoryName
from Orders o inner join Customers c on o.CustomerID=c.CustomerID
inner join Employees e on o.EmployeeID = e.EmployeeID inner join
[Order Details] od on o.OrderID=od.OrderiD inner join Products pon od.ProductID=p.ProductID inner join Suppliers s on
p.Supplierid=s.supplierid inner join Categories Ca on
p.Categoryid=Ca.CategoryID where month(o.orderdate)between 3 and 5 and year(o.orderdate)=1997
Constraint
1. Not null
2. Unique3. Check
4. Primary Key
5. Foreign Key
Not null
create table kct1(customername varchar(20))insert into kct1 values('aaa')
insert into kct1 values('')
insert into kct1 values('bbb')select * from kct1
drop table kct1
create table kct1(customername varchar(20)
63
8/8/2019 ASP Dot Net Full
64/74
constraint notnullcust not null)
insert into kct1 values('aaa')
insert into kct1 values('')insert into kct1 values('bbb')
select * from kct1
drop table kct1
Unique Constraint
create table kct1(codeno int)
insert into kct1 values(1001)
insert into kct1 values(1002)
insert into kct1 values(1003)insert into kct1 values(1001)
select * from kct1
drop table kct1
create table kct1(codeno int constraint unicodeno1 unique)
insert into kct1 values(1001)insert into kct1 values(1002)
insert into kct1 values(1003)
insert into kct1 values(1001)
select * from kct1drop table kct1
create table kct1(codeno int,constraint unicodeno1unique(codeno))
insert into kct1 values(1001)
insert into kct1 values(1002)insert into kct1 values(1003)
insert into kct1 values(1001)
select * from kct1drop table kct1
Soap 501 Soap 1 1
Soap Lux Soap 1 2Soap Hamam 1 3
Powder TSR 2 1Powder Ponds 2 2
create table kct1(codeno int constraint unicodeno1 unique,subcode int constraint unisubcode unique)
insert into kct1 values(1,1)
insert into kct1 values(2,2)
64
8/8/2019 ASP Dot Net Full
65/74
insert into kct1 values(1,3)
insert into kct1 values(3,1)
select * from kct1drop table kct1
create table kct1(codeno int,subcode int,constraint unicodesubcode unique(codeno,subcode))
insert into kct1 values(1,1)
insert into kct1 values(1,2)insert into kct1 values(1,3)
insert into kct1 values(2,1)
insert into kct1 values(2,2)
insert into kct1 values(2,3)insert into kct1 values(2,3)
select * from kct1
drop table kct1
Check Constraint
create table kct1(codeno int)insert into kct1 values(1001)
insert into kct1 values(1002)
insert into kct1 values(103)
select * from kct1drop table kct1
create table kct1(codeno int,constraint chkcodenocheck(codeno>1000))
insert into kct1 values(1001)
insert into kct1 values(1002)insert into kct1 values(103)
insert into kct1 values(1001)
select * from kct1drop table kct1
create table kct1(Codeno int,constraint unicodeno1 unique(codeno),
constraint chkcodeno check(codeno>1000))insert into kct1 values(1001)
insert into kct1 values(1002)
insert into kct1 values(103)insert into kct1 values(1001)
select * from kct1
drop table kct1
create table kct1(acctype char(2),constraint chkacctype
check(acctype in('SB','FD','CA')))
insert into kct1 values('SB')
65
8/8/2019 ASP Dot Net Full
66/74
insert into kct1 values('FD')
insert into kct1 values('ca')
insert into kct1 values('SA')select * from kct1
drop table kct1
Primary Key & Foreign Key
create table kct1(codeno int constraint pricodeno1 primary key)
insert into kct1 values(1)
insert into kct1 values(2)insert into kct1 values(3)
insert into kct1 values(4)
insert into kct1 values(1)
create table kct2(codeno int,constraint fore1
foreign key(codeno) references kct1(Codeno))
create table kct3(codeno int,constraint fore2
foreign key(codeno) references kct1(Codeno))
insert into kct2 values(1)
insert into kct2 values(1)
insert into kct2 values(1)insert into kct2 values(1)
insert into kct2 values(2)
insert into kct2 values(3)insert into kct2 values(5)
insert into kct3 values(1)
insert into kct3 values(1)
insert into kct3 values(1)
insert into kct3 values(1)insert into kct3 values(2)
insert into kct3 values(3)
insert into kct3 values(5)
select * from kct1
select * from kct2select * from kct3
delete from kct1 where codeno=1
delete from kct2 where codeno=1delete from kct3 where codeno=1
delete from kct1 where codeno=1
66
8/8/2019 ASP Dot Net Full
67/74
select * from kct1
select * from kct2
select * from kct3
drop table kct1
drop table kct2drop table kct3
drop table kct1
On Delete Cascade
create table kct1(codeno int constraint pricodeno1 primary key)
insert into kct1 values(1)
insert into kct1 values(2)insert into kct1 values(3)
insert into kct1 values(4)
insert into kct1 values(1)
create table kct2(codeno int,constraint fore1
foreign key(codeno) references kct1(Codeno) on delete cascade)
create table kct3(codeno int,constraint fore2
foreign key(codeno) references kct1(Codeno) on Delete cascade)
insert into kct2 values(1)
insert into kct2 values(1)
insert into kct2 values(1)insert into kct2 values(1)
insert into kct2 values(2)insert into kct2 values(3)insert into kct2 values(5)
insert into kct3 values(1)
insert into kct3 values(1)insert into kct3 values(1)
insert into kct3 values(1)
insert into kct3 values(2)insert into kct3 values(3)
insert into kct3 values(5)
select * from kct1
select * from kct2
select * from kct3
delete from kct1 where codeno=1
select * from kct1
67
8/8/2019 ASP Dot Net Full
68/74
select * from kct2
select * from kct3
drop table kct1
drop table kct2
drop table kct3drop table kct1
On Update Cascade
create table kct1(codeno int constraint pricodeno1 primary key)
insert into kct1 values(1)
insert into kct1 values(2)insert into kct1 values(3)
insert into kct1 values(4)
create table kct2(codeno int,constraint fore1
foreign key(codeno) references kct1(Codeno) on update cascade)
create table kct3(codeno int,constraint fore2
foreign key(codeno) references kct1(Codeno) on update cascade)
insert into kct2 values(1)
insert into kct2 values(1)
insert into kct2 values(1)insert into kct2 values(1)
insert into kct2 values(2)
insert into kct2 values(3)insert into kct2 values(5)
insert into kct3 values(1)
insert into kct3 values(1)
insert into kct3 values(1)
insert into kct3 values(1)insert into kct3 values(2)
insert into kct3 values(3)
insert into kct3 values(5)
select * from kct1
select * from kct2
select * from kct3
68
8/8/2019 ASP Dot Net Full
69/74
update kct1 set codeno=2 where codeno=1
select * from kct1select * from kct2
select * from kct3
drop table kct1
drop table kct2
drop table kct3drop table kct1
Outer Join
Left Outer Join
create table kct1(codeno int)
create table kct2(codeno int)
insert into kct1 values(1)
insert into kct1 values(2)insert into kct1 values(3)
insert into kct1 values(4)
insert into kct2 values(1)
insert into kct2 values(2)
insert into kct2 values(5)insert into kct2 values(6)
select * from kct1select * from kct2
select kct1.codeno,kct2.codeno from kct1 inner join kct2
on kct1.codeno=kct2.codeno
select kct1.codeno,kct2.codeno from kct1 left outer join kct2
on kct1.codeno=kct2.codeno
Right Outer Join
select kct1.codeno,kct2.codeno from kct1 right outer join kct2on kct1.codeno=kct2.codeno
Full Outer join
select kct1.codeno,kct2.codeno from kct1 full outer join kct2on kct1.codeno=kct2.codeno
69
8/8/2019 ASP Dot Net Full
70/74
Union
select codeno from kct1 union select codeno from kct2
Union All
select codeno from kct1 union all select codeno from kct2
Top
select orderid from orders order by orderidselect orderid from orders order by orderid desc
select max(orderid) as MaxOrder from orders
select max(orderid) as MaxOrder from orders whereOrderID
8/8/2019 ASP Dot Net Full
71/74
select Emp.EmpName from
(select firstname+' '+lastname as EmpName from employees) Emp
where Emp.EmpName like 'A%'order by Emp.EmpName
create database Kct
use Kct
create table Customer(CustomerNo int,CustomerName varchar(20))
create table Op(CustomerNo int,opBalance numeric)
create table Invoice(CustomerNo int,BillNo int,BillAmount numeric)
create table Receipt(CustomerNo int,RecAmount numeric)
insert into Customer values(1,'a')
insert into Customer values(2,'b')
insert into Customer values(3,'c')insert into Customer values(4,'d')
insert into Customer values(5,'e')
insert into op values(1,4500)
insert into op values(2,6000)
insert into invoice values(1,1,1500)
insert into invoice values(1,2,4500)
insert into invoice values(3,3,2500)insert into invoice values(3,4,1500)
insert into invoice values(4,5,2000)
insert into invoice values(4,6,3000)
insert into receipt values(1,1500)
insert into receipt values(1,2500)insert into receipt values(2,3000)
insert into receipt values(2,1500)
insert into receipt values(4,2500)
insert into receipt values(4,2000)
select * from Customer
select * from opselect * from invoice
select * from receipt
drop table Customerdrop table op
drop table invoice
drop table receipt
71
8/8/2019 ASP Dot Net Full
72/74
select c.customerno,c.customername,o.opbalance
from Customer c left outer join op o on c.Customerno=o.customerno
select c.customerno,c.customername,isnull(o.opbalance,0) as OpBalance
from Customer c left outer join op o on c.Customerno=o.customerno
select customerno,sum(billamount) as BillAmt from Invoice
group by customerno
select c.customerno,c.customername,isnull(o.opbalance,0) as OpBalance,
isnull(Bill.BillAmt,0) as BillAmt
from Customer c left outer join op o on c.Customerno=o.customerno
left outer join(select customerno,sum(billamount) as BillAmt from Invoice
group by customerno) Bill on c.customerno=Bill.CustomerNo
select c.customerno,c.customername,isnull(o.opbalance,0) as OpBalance,isnull(Bill.BillAmt,0) as BillAmt,
isnull(o.opbalance,0)+isnull(bill.billamt,0) as Totalfrom Customer c left outer join op o on c.Customerno=o.customerno
left outer join
(select customerno,sum(billamount) as BillAmt from Invoice
group by customerno) Bill on c.customerno=Bill.CustomerNo
select customerno,sum(recAmount) as RecAmount fromReceipt group by CustomerNo
select c.customerno,c.customername,isnull(o.opbalance,0) as OpBalance,isnull(Bill.BillAmt,0) as BillAmt,
isnull(o.opbalance,0)+isnull(bill.billamt,0) as Total,
isnull(Rec.RecAmount,0) as RecAmountfrom Customer c left outer join op o on c.Customerno=o.customerno
left outer join
(select customerno,sum(billamount) as BillAmt from Invoice
group by customerno) Bill on c.customerno=Bill.CustomerNoleft outer join
(select customerno,sum(recAmount) as RecAmount from
Receipt group by CustomerNo) Rec on c.CustomerNo=Rec.CustomerNo
select c.customerno,c.customername,isnull(o.opbalance,0) as OpBalance,
isnull(Bill.BillAmt,0) as BillAmt,isnull(o.opbalance,0)+isnull(bill.billamt,0) as Total,
isnull(Rec.RecAmount,0) as RecAmount,
isnull(o.opbalance,0) + isnull(bill.billamt,0)
- isnull(rec.recamount,0) as BalanceAmount
72
8/8/2019 ASP Dot Net Full
73/74
from Customer c left outer join op o on c.Customerno=o.customerno
left outer join
(select customerno,sum(billamount) as BillAmt from Invoicegroup by customerno) Bill on c.customerno=Bill.CustomerNo
left outer join
(select customerno,sum(recAmount) as RecAmount fromReceipt group by CustomerNo) Rec on c.CustomerNo=Rec.CustomerNo
select c.customerno,c.customername,isnull(o.opbalance,0) as OpBalance,isnull(Bill.BillAmt,0) as BillAmt,
isnull(o.opbalance,0)+isnull(bill.billamt,0) as Total,
isnull(Rec.RecAmount,0) as RecAmount,
isnull(o.opbalance,0) + isnull(bill.billamt,0)- isnull(rec.recamount,0) as BalanceAmount
from Customer c left outer join op o on c.Customerno=o.customerno
left outer join
(select customerno,sum(billamount) as BillAmt from Invoicegroup by customerno) Bill on c.customerno=Bill.CustomerNo
left outer join(select customerno,sum(recAmount) as RecAmount from
Receipt group by CustomerNo) Rec on c.CustomerNo=Rec.CustomerNo
where c.customerno=2
select customerno,customername from customer
select customerno,customername from customer where customerno=1
select customerno,customername,op=(select isnull(opbalance,0) from op where
customerno=1)from customer where customerno=1
select customerno,customername,op=(select isnull(opbalance,0) from op wherecustomerno=1),
BillAmt=(select isnull(sum(BillAmount),0) from invoice where customerno=1)
from customer where customerno=1
select customerno,customername,op=(select isnull(opbalance,0) from op where
customerno=1),
BillAmt=(select isnull(sum(BillAmount),0) from invoice where customerno=1),Total=(select isnull(opbalance,0) from op where customerno=1)
+(select isnull(sum(BillAmount),0) from Invoice where CustomerNo=1)
from customer where customerno=1
73
8/8/2019 ASP Dot Net Full
74/74
select customerno,customername,op=(select isnull(opbalance,0) from op where
customerno=1),
BillAmt=(select isnull(sum(BillAmount),0) from invoice where customerno=1),Total=(select isnull(opbalance,0) from op where customerno=1)
+(select isnull(sum(BillAmount),0) from Invoice where CustomerNo=1),
RecAmount=(select isnull(sum(RecAmount),0) from Receipt where CustomerNo=1)from customer where customerno=1
select customerno,customername,op=(select isnull(opbalance,0) from op wherecustomerno=1),
BillAmt=(select isnull(sum(BillAmount),0) from invoice where customerno=1),
Total=(select isnull(opbalance,0) from op where customerno=1)
+(select isnull(sum(BillAmount),0) from Invoice where CustomerNo=1),RecAmount=(select isnull(sum(RecAmount),0) from Receipt where CustomerNo=1),
Balance=(select isnull(opbalance,0) from op where customerno=1)
+(select isnull(sum(billamount),0) from invoice where customerno=1)
-(Select isnull(sum(recAmount),0) from Receipt where customerno=1)from customer where customerno=1
Procedure
alter procedure CustomerSelect
@CustomerNo intas
select customerno,customername,op=isnull((select opbalance
from op where customerno=@CustomerNo),0),Bill=isnull((select sum(billamount) from bill where customerno=@CustomerNo),0),
Balance=isnull((select opbalance from op where customerno=@CustomerNo),0)
+ isnull( (select sum(billamount) from bill where customerno=@CustomerNo),0),RecAmount=isnull((select sum(recamount) from receipt where
customerno=@CustomerNo),0),
TotalBalance=isnull((select opbalance from op where customerno=@CustomerNo),0)+ isnull((select sum(billamount) from bill where customerno=@CustomerNo),0)
- isnull((select sum(recamount) from receipt where customerno=@CustomerNo),0)
from
customer where customerno=@CustomerNoGO
exec CustomerSelect 1