Professional Documents
Culture Documents
C E R T I F I C A T E
REMARKS:
1|Page
DES’s NMITD AWT Journal MC1944
2|Page
DES’s NMITD AWT Journal MC1944
C. Data Tools(GridView, ToolStrip, BindingNavigator)
V A. LINQ Application to query
a. int array
b. var multidimensional array
c. Access DB
ASP .NET
VI A. PageEvents
B. PostBack and CrossPage Posting
C. Web Server Controls
D. Validation Controls
E. Design an e-Commerce WebSite using MasterPage, Theme and Skins.
F. Use AJAX controls to change Banner AD’s after every second, make use
of Adrotator Control.
VII A. Login and CreateUserWizard
B. GridView with AccessDataSource
C. GridView with SQLDataSource
D. GridView with ObjectDataSource
VIII A. ViewState Example
B. Cookies with multiple keys
C. Login Application with Cookies
D. Application to change Background Color based on selection. (Cookie)
E. Application to change Background Color based on selection. (Session)
F. Login Application with Session
G. Out-of-process Session State
H. SqlServer Session State
I. Cookieless Session
J. Application State
K. Output Cache:
VaryByParam
VaryByControl
VaryByCustom
L. Cache Object
Cache an ArrayList
Cache a DataSet
M. Shopping Cart Example
Web Services
IX A. Create an XML Web Service to add two integers. Consume
this service through a Web Client.
B. Create an XML Web Service with methods to calculate the
area and perimeter of a Rectangle. Consume this service through
a Windows client application.
C. Create an XML Web Service that returns all the branch details
from BranchTB. Write a Windows application that uses this
service to display branch details in a datagridview control.
D. Create an XML Web Service that returns the selected branch’s
3|Page
DES’s NMITD AWT Journal MC1944
4|Page
DES’s NMITD AWT Journal MC1944
C#
5|Page
DES’s NMITD AWT Journal MC1944
PRACTICAL NO.1
A. C# application to read and display user information
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Example1
{
public partial class Question1 : Form
{
public Question1()
{
InitializeComponent();
}
Output:
6|Page
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Example1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Output:
7|Page
DES’s NMITD AWT Journal MC1944
8|Page
DES’s NMITD AWT Journal MC1944
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Example1
{
public partial class Question1 : Form
{
public Question1()
{
InitializeComponent();
}
private void displayName_Click(object sender, EventArgs e)
{
num2.Text = "Welcome " + num1.Text;
MessageBox.Show("Welcome " + num1.Text);
}
Output:
9|Page
DES’s NMITD AWT Journal MC1944
10 | P a g e
DES’s NMITD AWT Journal MC1944
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class StringFunctionsProperties : Form
{
public StringFunctionsProperties()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string myname1 = myname.Text;
string str1 = @"C:\Users\ABC\Desktop";
}
}
}
Output:
11 | P a g e
DES’s NMITD AWT Journal MC1944
12 | P a g e
DES’s NMITD AWT Journal MC1944
namespace Eg1
{
public partial class Prac1_Q6 : Form
{
public Prac1_Q6()
{
InitializeComponent();
}
13 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
14 | P a g e
DES’s NMITD AWT Journal MC1944
namespace Eg1
{
public partial class Prac1_Q7 : Form
{
public Prac1_Q7()
{
InitializeComponent();
}
15 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
16 | P a g e
DES’s NMITD AWT Journal MC1944
a. continue
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i = 1;
string msg = "Numbers from 1 to 20 which are not divisible by 3
are:"+Environment.NewLine;
while(i<=20)
{
if(i%3==0)
{
i++;
continue;
}
else
{
msg += " " + i;
}
i++;
}
textBox1.Text = msg;
}
}
}
17 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
18 | P a g e
DES’s NMITD AWT Journal MC1944
b. goto
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i = 1;
string msg = "Numbers from 1 to 20 which are not divisible by 3
are:"+Environment.NewLine;
mylabel: while(i<=20)
{
if(i%3==0)
{
i++;
goto mylabel;
}
else
{
msg += " " + i;
}
i++;
}
textBox1.Text = msg;
}
}
}
19 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
20 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Example1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] arr = new int[10];
private void add_to_array_Click(object sender, EventArgs e)
{
string[] strarr = textBox1.Text.Split(' ');
for(int i=0;i<strarr.Length;i++)
{
arr[i] = Convert.ToInt16(strarr[i]);
}
MessageBox.Show("Number are added to array successfully.");
textBox2.Focus();
}
21 | P a g e
DES’s NMITD AWT Journal MC1944
{
MessageBox.Show("Number " + textBox2.Text + " not found. ");
textBox2.Focus();
textBox2.SelectAll();
}
}
Output:
22 | P a g e
DES’s NMITD AWT Journal MC1944
23 | P a g e
DES’s NMITD AWT Journal MC1944
B.cs(Class File)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
namespace deptB
{
namespace courseB
{
class B
{
public static void Display()
{
MessageBox.Show("Inside namespace
deptB.courseB.classB.Display()","Inside B", MessageBoxButtons.OKCancel);
}
}
}
}
}
A.cs (Class File)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Eg1.deptB.courseB;
using System.Windows.Forms;
namespace Eg1
{
namespace deptA
{
namespace courseA
{
class A
{
public static void Display()
24 | P a g e
DES’s NMITD AWT Journal MC1944
{
MessageBox.Show("Inside namespace
deptA.courseA.classA.Display()", "Inside A", MessageBoxButtons.OKCancel);
B.Display();
}
}
}
}
}
NamespaceDemo.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Eg1.deptA.courseA;
using System.Windows.Forms;
namespace Eg1
{
public partial class NamespaceDemo : Form
{
public NamespaceDemo()
{
InitializeComponent();
}
25 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
26 | P a g e
DES’s NMITD AWT Journal MC1944
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
static class Program
{
public static string[] sub;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(String[] args)
{
sub = args;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Prac1_Q11());
}
}
}
27 | P a g e
DES’s NMITD AWT Journal MC1944
Prac1_Q11.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Prac1_Q11 : Form
{
public Prac1_Q11()
{
InitializeComponent();
}
28 | P a g e
DES’s NMITD AWT Journal MC1944
namespace Eg1
{
public partial class Practical2 : Form
{
public Practical2()
{
InitializeComponent();
}
29 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
30 | P a g e
DES’s NMITD AWT Journal MC1944
c. Display the values before and after calling the swap function.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class SwapExample : Form
{
public SwapExample()
{
InitializeComponent();
}
31 | P a g e
DES’s NMITD AWT Journal MC1944
Swap by value
32 | P a g e
DES’s NMITD AWT Journal MC1944
Swap by reference
33 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical2_Q3 : Form
{
public Practical2_Q3()
{
InitializeComponent();
}
34 | P a g e
DES’s NMITD AWT Journal MC1944
ename = value;
}
}
}
public int Esalary
{
get { return salary; }
}
public int Eage
{
get;
set;
}
}
}
Output:
35 | P a g e
DES’s NMITD AWT Journal MC1944
c. Two Constructors.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical2_Q4 : Form
{
public Practical2_Q4()
{
InitializeComponent();
}
36 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
37 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class StructureExample : Form
{
public StructureExample()
{
InitializeComponent();
}
38 | P a g e
DES’s NMITD AWT Journal MC1944
}
}
}
Output:
39 | P a g e
DES’s NMITD AWT Journal MC1944
ClassArea.cs(Class File)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Eg1
{
class ClassArea
{
}
partial class Square
{
public Square(double side)
{
this.side = side;
}
public void Area()
{
System.Windows.Forms.MessageBox.Show("Area= " + side * side +
" sq.cm");
}
}
}
ClassPeri.cs(Class File)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Eg1
{
class ClassPeri
{
}
partial class Square
{
private double side;
public void Peri()
{
System.Windows.Forms.MessageBox.Show("Perimeter= " + 4*side +
" cm");
}
40 | P a g e
DES’s NMITD AWT Journal MC1944
}
}
Practical2_Q6(Windows Form File)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical2_Q6 : Form
{
Square s;
public Practical2_Q6()
{
InitializeComponent();
}
41 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
42 | P a g e
DES’s NMITD AWT Journal MC1944
Person.cs(Class File)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
class Person
{
protected string sname;
protected int uid;
public Person(string sname,int uid)
{
this.sname = sname;
this.uid = uid;
}
public virtual void getInfo()
{
MessageBox.Show("Inside Base Class getInfo");
MessageBox.Show("Name: " + sname + " UID: " + uid);
}
}
}
Employee1.cs(Class File)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
class Employee1:Person
{
protected int eid;
public Employee1(string sname,int uid,int eid):base(sname,uid)
43 | P a g e
DES’s NMITD AWT Journal MC1944
{
this.eid = eid;
}
public override void getInfo()
{
base.getInfo();
MessageBox.Show("Inside Derived Class getInfo");
MessageBox.Show("Name: " + sname + " UID: " + uid+" EMPID:
"+eid);
}
}
}
Practical2Q7.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical2Q7 : Form
{
public Practical2Q7()
{
InitializeComponent();
}
44 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
45 | P a g e
DES’s NMITD AWT Journal MC1944
namespace Eg1
{
interface IFormPropD
{
void getFormColD(Form F);
}
interface IButtonPropD
{
void getBtnColB(Button B);
}
class RetrieveProperties:IFormPropD,IButtonPropD
{
public void getFormColD(Form F)
{
MessageBox.Show("Form Color: " + F.BackColor.ToString());
}
public void getBtnColB(Button B)
{
MessageBox.Show("Button Color: " + B.BackColor.ToString());
}
public void Display()
{
MessageBox.Show("Inside display");
}
}
}
InterfaceExamplecs.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class InterfaceExamplecs : Form
{
public InterfaceExamplecs()
{
46 | P a g e
DES’s NMITD AWT Journal MC1944
InitializeComponent();
}
47 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical3_Q1 : Form
{
TextBox[] txtnames = new TextBox[5];
TextBox[] txtsub1 = new TextBox[5];
TextBox[] txtsub2 = new TextBox[5];
public Practical3_Q1()
{
InitializeComponent();
}
48 | P a g e
DES’s NMITD AWT Journal MC1944
49 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
50 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical3_Q2 : Form
{
public Practical3_Q2()
{
InitializeComponent();
}
Emp2[] emp = new Emp2[4];
int count = 0;
51 | P a g e
DES’s NMITD AWT Journal MC1944
{
total += i.BasicPay;
}
MessageBox.Show("Total of all employee basic pay is :" + total);
}
}
class Emp2
{
public string Name
{
get;
set;
}
public int EmpID
{
get;
set;
}
public int BasicPay
{
get;
set;
}
}
}
52 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
53 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Practical3_Q_3 : Form
{
public Practical3_Q_3()
{
InitializeComponent();
}
public int[,,] a = new int[,,]
{
{ { 1,2}, {3,4 } },
{ { 5,6}, {7,8 } },
{ { 9,10}, {11,12 } }
};
private void button1_Click(object sender, EventArgs e)
{
int total = 0;
for (int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
total += a[i, j, k];
}
}
}
MessageBox.Show("Total of all element in array is: " + total);
}
}
}
54 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
55 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
string s = "";
private void button1_Click(object sender, EventArgs e)
{
int[][] jagged = new int[3][];
/*
jagged[0]=new int[3];
jagged[0][0]=1;
jagged[0][1]=2;
jagged[0][2]=3;
jagged[1]=new int[6];
jagged[1][0]=4;
jagged[1][1]=5;
jagged[1][2]=6;
jagged[1][3]=7;
jagged[1][4]=8;
jagged[1][5]=9;
jagged[2]=new int[4];
jagged[2][0]=10;
jagged[2][1]=11;
jagged[2][2]=12;
jagged[2][3]=13;
*/
jagged = new int[3][] { new int[3] { 1, 2, 3 }, new int[6] { 4, 5, 6, 7,
8, 9 }, new int[4] { 10, 11, 12, 13 } };
56 | P a g e
DES’s NMITD AWT Journal MC1944
for(int i=0;i<jagged.Length;i++)
{
s = "";
int[] intArray = jagged[i];
for(int a=0;a<intArray.Length;a++)
{
s += intArray[a] + " ";
}
MessageBox.Show("Inner Array " + (i + 1) + "'s values " + s);
}
Application.Exit();
}
}
}
Output:
57 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
58 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
59 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class CopyClone : Form
{
public CopyClone()
{
InitializeComponent();
}
60 | P a g e
DES’s NMITD AWT Journal MC1944
61 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
62 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class SortExample : Form
{
public SortExample()
{
InitializeComponent();
}
63 | P a g e
DES’s NMITD AWT Journal MC1944
{
set;
get;
}
public int CompareTo(Emp1 obj)
{
int Result = this.EName.CompareTo(obj.EName);
MessageBox.Show(Result.ToString());
return Result;
}
}
}
Output:
64 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eg1
{
public partial class AA : Form
{
public AA()
{
InitializeComponent();
}
65 | P a g e
DES’s NMITD AWT Journal MC1944
class Coord
{
private int x;
private int y;
public Coord()
{
}
public Coord(int i,int j)
{
x = i;
y = j;
}
public void ShowXY()
{
MessageBox.Show("Number 1= " + x + " Number 2= " + y);
}
public void ShowXY1()
{
MessageBox.Show("Number 3= " + x + " Number 4= " + y);
}
public void ShowXY3()
{
MessageBox.Show("Number 1+Number 3= " + x + " Number
2+Number 4= " + y);
}
public static Coord operator ++(Coord c)
{
Coord temp = new Coord();
temp.x = ++c.x;
temp.y = ++c.y;
return temp;
}
public static Coord operator +(Coord c1,Coord c2)
{
Coord temp = new Coord();
temp.x = c1.x + c2.x;
temp.y = c1.y + c2.y;
return temp;
}
}
}
66 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
67 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO.2
A. C# application to simulate a Bank Account with exception handling
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace prac3
{
public partial class Bank : Form
{
Account a = new Account();
public Bank()
{
InitializeComponent();
}
a.Check(textBox2.Text);
double amt = Convert.ToDouble(textBox2.Text);
a = new Account(cname, amt);
MessageBox.Show("Account Created");
listBox1.Items.Add(a.GetDetails());
}
catch (EmptyFields ef) {
ef.display();
MessageBox.Show(ef.Message);
}
catch (ArgumentException aex)
{
MessageBox.Show(aex.Message);
textBox2.Focus();
}
}
class Account {
private string CName {
get;
set;
68 | P a g e
DES’s NMITD AWT Journal MC1944
}
private double Balance {
get;
set;
}
public Account(String name, double bal) {
CName = name;
Balance = bal;
}
public Account() :this("",0.0) {
}
}
public void display() {
MessageBox.Show("Name and Amount can not be blank...");
}
}
69 | P a g e
DES’s NMITD AWT Journal MC1944
MessageBox.Show("Amount Deposited");
listBox1.Items.Add(a.GetDetails());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
70 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
71 | P a g e
DES’s NMITD AWT Journal MC1944
72 | P a g e
DES’s NMITD AWT Journal MC1944
73 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace prac3
{
public partial class Loan : Form
{
decimal p, n, r, si, t;
double ci;
public Loan()
{
InitializeComponent();
}
p = Convert.ToDecimal(textBox1.Text);
n = Convert.ToDecimal(textBox2.Text);
r = Convert.ToDecimal(textBox3.Text);
74 | P a g e
DES’s NMITD AWT Journal MC1944
}
}
p = Convert.ToDecimal(textBox1.Text);
n = Convert.ToDecimal(textBox2.Text);
r = Convert.ToDecimal(textBox3.Text);
t = Convert.ToDecimal(textBox4.Text);
}
}
}
}
75 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
76 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace prac3
{
public partial class Cal : Form
{
Double resultValue = 0;
String operationPerformed = "";
bool isOperationPerformed = false;
public Cal()
{
InitializeComponent();
}
isOperationPerformed = false;
Button button = (Button)sender;
if (button.Text == ".")
{
if (!textBox1.Text.Contains("."))
{
textBox1.Text = textBox1.Text + button.Text;
}
}
else
{
77 | P a g e
DES’s NMITD AWT Journal MC1944
if (resultValue != 0) {
button16.PerformClick();
operationPerformed = button.Text;
labelCurrentOperation.Text = resultValue + " " +
operationPerformed;
isOperationPerformed = true;
}
else
{
operationPerformed = button.Text;
resultValue = Double.Parse(textBox1.Text);
labelCurrentOperation.Text = resultValue + " " +
operationPerformed;
isOperationPerformed = true;
}
try {
switch (operationPerformed)
{
case "+":
textBox1.Text = (resultValue +
Double.Parse(textBox1.Text)).ToString();
break;
case "-":
textBox1.Text = (resultValue -
Double.Parse(textBox1.Text)).ToString();
break;
case "*":
textBox1.Text = (resultValue *
Double.Parse(textBox1.Text)).ToString();
break;
case "/":
78 | P a g e
DES’s NMITD AWT Journal MC1944
textBox1.Text = (resultValue /
Double.Parse(textBox1.Text)).ToString();
break;
default: break;
}
resultValue = Double.Parse(textBox1.Text);
labelCurrentOperation.Text = "";
}
catch (Exception ae) {
MessageBox.Show(ae.Message);
}
}
}
}
Output :
79 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace prac1_1
{
public partial class Form1 : Form
{
ArrayList a1 = new ArrayList();
public Form1()
{
InitializeComponent();
}
80 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
81 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace prac1_1
{
public partial class Form1 : Form
{
List<string> laptops = new List<string>();
public Form1()
{
InitializeComponent();
}
}
}
82 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
83 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
a = Convert.ToInt16 (textBox1.Text);
b = Convert.ToInt16 (textBox2.Text);
//call swap
Swap<int>(ref a, ref b);
84 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
85 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace prac1_1
{
public partial class Form1 : Form
{
Stack<Employee> stackEmployees = new Stack<Employee>();
public Form1()
{
InitializeComponent();
}
86 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
87 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO.3
A. File Information Application
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace prac5
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
textBox2.Text = theDir.FullName;
string CurrentFolderPath = theDir.FullName;
if (theDir.Exists) {
88 | P a g e
DES’s NMITD AWT Journal MC1944
textBox3.Text = currFile.FullName;
textBox4.Text = currFile.FullName.Length.ToString();
textBox5.Text = currFile.CreationTime.ToLongTimeString();
textBox7.Text = currFile.LastWriteTime.ToLongDateString();
textBox6.Text = currFile.LastAccessTime.ToLongDateString();
89 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
90 | P a g e
DES’s NMITD AWT Journal MC1944
91 | P a g e
DES’s NMITD AWT Journal MC1944
92 | P a g e
DES’s NMITD AWT Journal MC1944
93 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace prac5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Output :
94 | P a g e
DES’s NMITD AWT Journal MC1944
95 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace prac5
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
int b = fs.ReadByte();
while (b != -1) {
textBox2.Text += (char)b;
b = fs.ReadByte();
}
fs.Close();
}
96 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
97 | P a g e
DES’s NMITD AWT Journal MC1944
98 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace prac5
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
99 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
100 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace prac5
{
public partial class NotepadApp : Form
{
public NotepadApp()
{
InitializeComponent();
}
101 | P a g e
DES’s NMITD AWT Journal MC1944
Output :
102 | P a g e
DES’s NMITD AWT Journal MC1944
103 | P a g e
DES’s NMITD AWT Journal MC1944
104 | P a g e
DES’s NMITD AWT Journal MC1944
105 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO.4
A. Bank Application Connected DB -> Change ListView View to Detail
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Eg1
{
public partial class DatabaseEg1 : Form
{
public DatabaseEg1()
{
InitializeComponent();
}
106 | P a g e
DES’s NMITD AWT Journal MC1944
cmd.ExecuteScalar();
con.Close();
listView1.Items.Clear();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox1.Focus();
button1_Click(sender,e);
}
}
}
Output :
107 | P a g e
DES’s NMITD AWT Journal MC1944
108 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace DBprac
{
public partial class Form3 : Form
{
DataSet ds;
OleDbDataAdapter da;
OleDbConnection con;
OleDbCommandBuilder bldr;
public Form3()
{
InitializeComponent();
}
109 | P a g e
DES’s NMITD AWT Journal MC1944
ds.Tables["Emp"].Rows.Add(drnew);
da.Update(ds, "Emp");
MessageBox.Show("Record added");
dataGridView1.DataSource = ds.Tables["Emp"];
}
this.BindingContext[ds.Tables[0]].Position = 0;
this.BindingContext[ds.Tables[0]].Position = ds.Tables[0].Rows.Count -
1;
if (this.BindingContext[ds.Tables[0]].Position <
ds.Tables[0].Rows.Count - 1)
{
this.BindingContext[ds.Tables[0]].Position += 1;
}
110 | P a g e
DES’s NMITD AWT Journal MC1944
111 | P a g e
DES’s NMITD AWT Journal MC1944
Step 2: For attaching BindingNavigator and GridView, Drag and drop Binding
Source. It will not seen on windows for but it will be outside the window form.
Step 3: Configure BindingSource
- Configure Data Source to database
- Configure Data Member to Table
Output :
PRACTICAL NO. 5
112 | P a g e
DES’s NMITD AWT Journal MC1944
113 | P a g e
DES’s NMITD AWT Journal MC1944
114 | P a g e
DES’s NMITD AWT Journal MC1944
On Load Access DB
On Find Employee
115 | P a g e
DES’s NMITD AWT Journal MC1944
116 | P a g e
DES’s NMITD AWT Journal MC1944
ASP.NET
117 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO. 6
A. Page Events
Solution:
using System;
namespace asp_practicals.practical_1 {
118 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
119 | P a g e
DES’s NMITD AWT Journal MC1944
120 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Title102.aspx
using System;
namespace asp_practicals.practical_1 {
title102_add_on.aspx
using System;
using System.Web.UI.WebControls;
namespace asp_practicals.practical_1 {
TextBox textbox2;
Calendar calender2;
121 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
122 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
using System;
namespace asp_practicals.practical_1 {
if (FileUpload1.HasFile) {
else {
if (RadioButton1.Checked) {
} else {
if (RadioButton2.Checked) {
} else {
123 | P a g e
DES’s NMITD AWT Journal MC1944
Image2.Visible = true;
Output:
124 | P a g e
DES’s NMITD AWT Journal MC1944
D. Validation Controls
Solution:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
function ValidateNo(){
if((parseInt(document.forms[0].TextBox6.value)%2)==0){
alert("Even Number");
else {
alert("Odd Number");
</script>
</head>
<body>
<div>
Enter your
name: &n
bsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1" ErrorMessage="This is required
field" ForeColor="#990000">*</asp:RequiredFieldValidator>
<br />
<br />
125 | P a g e
DES’s NMITD AWT Journal MC1944
Enter
password:
<br />
<br />
<br />
<br />
Enter age:
<br />
<br />
Enter your
email: &nb
sp;
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox5"
ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-
+.']\w+)*@\w+([-.]\w+)*\.\w+
([-.]\w+)*"></asp:RegularExpressionValidator>
<br />
<br />
<br />
<br />
126 | P a g e
DES’s NMITD AWT Journal MC1944
<br />
<br />
</div>
</form>
</body>
</html>
Output:
127 | P a g e
DES’s NMITD AWT Journal MC1944
128 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Site.master
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head"
runat="server"></asp:ContentPlaceHolder>
<style type="text/css">
.auto-style1 {
height: 51px;
</style>
</head>
<body>
<table border="1">
<tr>
</td>
</tr>
<tr>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server"></asp:ContentPlaceHolder>
</td>
<td style="width:60%">
129 | P a g e
DES’s NMITD AWT Journal MC1944
<asp:ContentPlaceHolder ID="ContentPlaceHolder2"
runat="server"></asp:ContentPlaceHolder>
</td>
</tr>
<tr>
</td>
<td style="width:60%">
<asp:ContentPlaceHolder ID="ContentPlaceHolder3"
runat="server"></asp:ContentPlaceHolder>
</td>
</tr>
</table>
</form>
</body>
</html>
130 | P a g e
DES’s NMITD AWT Journal MC1944
Title105.aspx
</asp:Content>
<p>
</p>
<p>
&n
bsp; &nbs
p;
</p>
</asp:Content>
<p>
</p>
</asp:Content>
131 | P a g e
DES’s NMITD AWT Journal MC1944
Title105.aspx.cs
using System;
namespace asp_practicals.practical_1.title105 {
Output:
132 | P a g e
DES’s NMITD AWT Journal MC1944
133 | P a g e
DES’s NMITD AWT Journal MC1944
F. Use AJAX controls to change Banner AD’s after every second, make
use of Ad rotator Control.
Solution:
XMLFile1.xml
<Advertisements>
<Ad>
<ImageUrl>~/practical_1/images/google.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>Visit Google.com</AlternateText>
<Impressions>80</Impressions>
<Keyword>Search</Keyword>
</Ad>
<Ad>
<ImageUrl>~/practical_1/images/yahoo.jpg</ImageUrl>
<NavigateUrl>http://www.yahoo.com</NavigateUrl>
<AlternateText>Visit Yahoo.com</AlternateText>
<Impressions>80</Impressions>
<Keyword>Search</Keyword>
</Ad>
<Ad>
<ImageUrl>~/practical_1/images/msn.jpg</ImageUrl>
<NavigateUrl>http://www.msn.com</NavigateUrl>
<AlternateText>Visit msn.com</AlternateText>
<Impressions>80</Impressions>
<Keyword>Search</Keyword>
</Ad>
</Advertisements>
134 | P a g e
DES’s NMITD AWT Journal MC1944
Title106.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<br />
<asp:ScriptManager ID="ScriptManager1"
runat="server"></asp:ScriptManager>
<br />
<br />
<ContentTemplate>
</asp:Timer>
<br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</form>
</body>
</html>
135 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
136 | P a g e
DES’s NMITD AWT Journal MC1944
137 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO. 7
A. Login and CreateUserWizard
Solution:
Title201.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1"
runat="server"></asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1"
runat="server"></asp:CompleteWizardStep>
</WizardSteps>
138 | P a g e
DES’s NMITD AWT Journal MC1944
</asp:CreateUserWizard>
<br />
</div>
</form>
</body>
</html>
Title201(login).aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
139 | P a g e
DES’s NMITD AWT Journal MC1944
</asp:Login>
<br />
</div>
</form>
</body>
</html>
Title201.aspx.cs
using System;
namespace asp_practicals.practical_2 {
Response.Redirect("~/practical_2/tilte201(login).aspx");
Title201(login).aspx.cs
using System;
namespace asp_practicals.practical_2 {
Response.Redirect("~/practical_2/title201(Successfull).aspx");
140 | P a g e
DES’s NMITD AWT Journal MC1944
Title201(success).aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</div>
</form>
</body>
</html>
Output:
141 | P a g e
DES’s NMITD AWT Journal MC1944
142 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Title202.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<Columns>
</asp:BoundField>
</asp:BoundField>
</asp:BoundField>
143 | P a g e
DES’s NMITD AWT Journal MC1944
</asp:BoundField>
</asp:BoundField>
</Columns>
</asp:GridView>
<br />
</div>
</form>
</body>
</html>
144 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
145 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Title203.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
table, th, td {
margin:5px;
padding:5px;
</style>
</head>
<body>
<h2>Account Info</h2>
<table style="width:50%;">
<tr>
<td>ACCOUNTS INFO:</td>
<td></td>
</tr>
<tr>
<td>Enter CustomerID:</td>
<td>
146 | P a g e
DES’s NMITD AWT Journal MC1944
</td>
</tr>
<tr>
<td>
VIEW
</td>
<td>
</asp:GridView>
</td>
</tr>
147 | P a g e
DES’s NMITD AWT Journal MC1944
<tr>
<td>BRANCH INFO:</td>
<td></td>
</tr>
<tr>
<td>BRANCH NAME:</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
Title203.aspx.cs
using System;
using System.Data.SqlClient;
using System.Configuration;
namespace asp_practicals.practical_2 {
148 | P a g e
DES’s NMITD AWT Journal MC1944
SqlDataSource1.DataBind();
GridView1.DataSource = SqlDataSource1;
GridView1.DataBind();
conn.Open();
cmd.Parameters.AddWithValue("@AcNo", txt_cut_id.Text);
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
conn.Close();
conn.Open();
cmd.Parameters.AddWithValue("@BranchId", ddl_branchId.SelectedValue);
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
conn.Close();
149 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
150 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Title204.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</asp:GridView>
</div>
151 | P a g e
DES’s NMITD AWT Journal MC1944
</form>
</body>
</html>
Output:
152 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO. 8
A. View State Example
Solution:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
int count = 0;
if (!IsPostBack) {
TextBox1.Text = "0";
count++;
TextBox1.Text = count.ToString();
if (ViewState["clk"] != null) {
TextBox1.Text = count.ToString();
ViewState["clk"] = count;
153 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
On Submit Button
154 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Cookie Form:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class WebForm7: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Response.Cookies.Add(cookie1);
Response.Write("Cookie Created");
}
namespace WebApplication1 {
public partial class CookieRead: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
HttpCookie ck1 = Request.Cookies["Info"];
if (ck1 != null) {
Label1.Text = ck1["Fname"];
155 | P a g e
DES’s NMITD AWT Journal MC1944
Label2.Text = ck1["Lname"];
}
}
}
}
Output:
Create Cookie
Show Cookie
Delete Cookie
156 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1 {
if (!IsPostBack) {
if (Request.Cookies["username"] != null) {
TextBox1.Text = Request.Cookies["username"].Value;
if (Request.Cookies["password"] != null) {
TextBox1.Text = Request.Cookies["password"].Value;
CheckBox1.Checked = true;
157 | P a g e
DES’s NMITD AWT Journal MC1944
adapt.Fill(ds);
if (ds.Tables[0].Rows.Count > 0) {
if (CheckBox1.Checked == true) {
Response.Cookies["username"].Value = TextBox1.Text;
Response.Cookies["password"].Value = TextBox2.Text;
Response.Cookies["username"].Expires = DateTime.Now.AddDays(15);
Response.Cookies["password"].Expires = DateTime.Now.AddDays(15);
} else {
Response.Cookies["username"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["password"].Expires = DateTime.Now.AddDays(-1);
Response.Redirect("~/welcome.aspx");
} else {
using System;
using System.Collections.Generic;
using System.Linq;
158 | P a g e
DES’s NMITD AWT Journal MC1944
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
if (ck1 != null) {
Label1.Text = ck1.Value;
Output:
159 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
if (Request.Cookies["Bgcolor"] != null) {
DropDownList1.SelectedValue = Request.Cookies["Bgcolor"].Value;
BodyTag.Style["background-color"] = DropDownList1.SelectedValue;
BodyTag.Style["background-color"] = DropDownList1.SelectedValue;
cookie.Value = DropDownList1.SelectedValue;
cookie.Expires = DateTime.Now.AddHours(-1);
Response.SetCookie(cookie);
160 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
161 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
if (Session["Bgcolor"] != null) {
DropDownList1.SelectedValue = Session["Bgcolor"].ToString();
BodyTag.Style["background-color"] = DropDownList1.SelectedValue;
BodyTag.Style["background-color"] = DropDownList1.SelectedValue;
Session["Bgcolor"] = DropDownList1.SelectedValue;
162 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
163 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Session Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class SessionUser: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
namespace WebApplication1 {
public partial class Home: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (Session["uname"] != null && Session["uname"] != "") {
Label1.Text = Session["uname"].ToString();
}
}
}
}
164 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
165 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Outofprocess.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="outofprocess.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form2" runat="server">
<div>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Username"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"
TextMode="Password"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Login" />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Outprocess.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
166 | P a g e
DES’s NMITD AWT Journal MC1944
using System.Web.UI.WebControls;
public partial class _Default: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {}
protected void Button1_Click(object sender, EventArgs e) {
Session["Name"] = TextBox1.Text;
Response.Redirect("~/WebForm1.aspx");
}
}
Webform1.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class webform1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "welcome" + Session["name"].ToString();
}
}
Output:
167 | P a g e
DES’s NMITD AWT Journal MC1944
168 | P a g e
DES’s NMITD AWT Journal MC1944
Solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class SQLsessionuser: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
namespace WebApplication1 {
public partial class Home: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (Session["uname"] != null) {
Label1.Text = Session["uname"].ToString();
} else {
Label1.Text = "Anonymous User";
}
}
}
}
Note: Add this line to the web.config in a new <system.web> tag
“<sessionState mode="SQLServer" sqlConnectionString="Data
Source=DESKTOP-0NRI8FC;Integrated Security=SSPI"
timeout="20"></sessionState>”
169 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
Again the rerunning the program after the stopping the site
170 | P a g e
DES’s NMITD AWT Journal MC1944
I. Cookieless Session
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class Cookieless: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class Home: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (Session["data"] != null) {
Label1.Text = Session["data"].ToString();
} else {
Label1.Text = "Anonymous User";
}
}
}
}
171 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
Cookie Page:
Home Page:
172 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class WebForm10: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Application["visits"] = (int) Application["visits"] + 1;
Label1.Text = "The No of Visits" + Application["visits"].ToString();
}
}
}
Globab.asax
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace WebApplication1 {
public class Global: System.Web.HttpApplication {
173 | P a g e
DES’s NMITD AWT Journal MC1944
}
}
}
Output:
174 | P a g e
DES’s NMITD AWT Journal MC1944
K. Output Cache
Solution:
Vary by Param
Web Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class WebForm11: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Label1.Text = DateTime.Now.ToString();
}
}
Form Source:
175 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
Vary By Control
Web Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class WebForm12: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Label2.Text = DateTime.Now.ToLongTimeString();
}
176 | P a g e
DES’s NMITD AWT Journal MC1944
Form Source:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm12.aspx.cs" Inherits="WebApplication1.WebForm12" %>
<%@ OutputCache Duration="30" VaryByControl="DropDownList1"
VaryByParam="none"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Option One</asp:ListItem>
<asp:ListItem>Option Two</asp:ListItem>
<asp:ListItem>Option Three</asp:ListItem>
</asp:DropDownList>
<br />
<br />
The page will be rendered from cache basing on the selected item of
DropDown List.<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Output:
177 | P a g e
DES’s NMITD AWT Journal MC1944
Vary By Custom:
Web Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 {
public partial class VaryByCustom: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
}
}
178 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
FireFox
Microsoft Edge
179 | P a g e
DES’s NMITD AWT Journal MC1944
L. Cache Object
Solution:
Cache a DataSet
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1 {
public partial class DataCache: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Cache["Data"] = ds;
Label1.Text = "Data Loaded from DB";
} else {
GridView1.DataSource = (DataSet) Cache["Data"];
GridView1.DataBind();
Label1.Text = "Data Loaded from Cache";
}
}
}
}
180 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
181 | P a g e
DES’s NMITD AWT Journal MC1944
Cache an ArrayList
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace WebApplication1 {
public partial class CacheArrayList: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ArrayList datestamps;
if (Cache["datestamps"] == null) {
datestamps = new ArrayList();
datestamps.Add(DateTime.Now);
datestamps.Add(DateTime.Now.AddDays(1));
datestamps.Add(DateTime.Now.AddDays(2));
Cache.Add("datestamps", datestamps, null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
new TimeSpan(0, 0, 60), System.Web.Caching.CacheItemPriority.Default,
null);
} else {
datestamps = (ArrayList) Cache["datestamps"];
foreach(DateTime dt in datestamps) {
Response.Write(dt.ToString() + "<br/>");
}
}
}
}
}
Output:
182 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:
Webform2.aspx
183 | P a g e
DES’s NMITD AWT Journal MC1944
Webform2.aspx.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
namespace AssiASP {
public partial class WebForm2: System.Web.UI.Page {
OleDbConnection con;
OleDbCommand cmd;
OleDbDataReader dr;
protected void Page_Load(object sender, EventArgs e) {}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e) {
ArrayList SelectedProductList;
if (Session["cart"] == null) {
//cart is empty
SelectedProductList = new ArrayList();
Cart cart = new Cart();
//retrive selected product id
cart.productid =
Convert.ToInt32(GridView1.DataKeys[GridView1.SelectedIndex].Value);
//retrieve product name and price
con = new
OleDbConnection(@ "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source = C: \Users\ pc - 1\ Documents\ Database7.accdb ");
con.Open(); cmd = new OleDbCommand("select * from shopping where
Id=" +
cart.productid, con); dr = cmd.ExecuteReader(); dr.Read();
cart.productname = dr["name1"].ToString();; cart.price =
Convert.ToInt32(dr["price"]);
// add cart to list
SelectedProductList.Add(cart); Session["cart"] = SelectedProductList;
}
else {
184 | P a g e
DES’s NMITD AWT Journal MC1944
Convert.ToInt32(GridView1.DataKeys[GridView1.SelectedIndex].Value);
con = new
OleDbConnection(@ "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source = C: \Users\ pc - 1\ Documents\ Database7.accdb ");
con.Open(); cmd = new OleDbCommand("select * from shopping
where Id=" +
cart.productid, con); dr = cmd.ExecuteReader(); dr.Read();
cart.productname = dr["name1"].ToString();; cart.price =
Convert.ToInt32(dr["price"]); SelectedProductList = (ArrayList) Session["cart"];
SelectedProductList.Add(cart);
}
}
}
}
Cart.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AssiASP {
public class Cart {
public int productid;
public string productname;
public int price;
}
}
Mycart.aspx
185 | P a g e
DES’s NMITD AWT Journal MC1944
</html>
Mycart.aspx.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AssiASP {
public partial class Mycart: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Cart cartobj = null;
ArrayList productList = (ArrayList) Session["cart"];
if (productList != null) {
for (int i = 0; i < productList.Count; i++) {
cartobj = (Cart) productList[i];
Response.Write("<b/><b> Product ID </b> " + cartobj.productid);
Response.Write("<br/><b> Product Name </b> " +
cartobj.productname +
"<br/> <b>Price </b> " + cartobj.price);
}
} else Response.Write("Cart is empty");
}
}
}
Ecom.Master
<%@ Master Language="C#" AutoEventWireup="true"
CodeBehind="ecom.master.cs" Inherits="AssiASP.ecom" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>C1747</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
186 | P a g e
DES’s NMITD AWT Journal MC1944
}
li a {
font-size:30px;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
#header{
background-color: black;
color:white;
margin:0px;
font-family:cursive;
font-size:30px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="header">
<center>Shopping Cart</center>
</div>
<div>
<center>
<ul>
<li><a class="active" href="Home.aspx">Home</a></li>
<li><a href="addProduct.aspx">Add Products</a></li>
<li><a href="viewProduct.aspx">Display Products</a></li>
</ul>
</center>
</div>
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
187 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
188 | P a g e
DES’s NMITD AWT Journal MC1944
Web
Services
189 | P a g e
DES’s NMITD AWT Journal MC1944
PRACTICAL NO.9
A. Create an XML Web Service to add two integers. Consume this service
through a Web Client.
Solution:-
CalcService.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace webservice2 {
/// <summary>
/// Summary description for CalcService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class CalcService: System.Web.Services.WebService {
[WebMethod]
public int Add(int a, int b) {
return a + b;
}
}
}
190 | P a g e
DES’s NMITD AWT Journal MC1944
191 | P a g e
DES’s NMITD AWT Journal MC1944
192 | P a g e
DES’s NMITD AWT Journal MC1944
Webform1.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Clientwebservice {
public partial class WebForm1: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
Label1.Text = (client.Add(Convert.ToInt16(TextBox1.Text),
Convert.ToInt16(TextBox2.Text))).ToString();
}
}
}
193 | P a g e
DES’s NMITD AWT Journal MC1944
194 | P a g e
DES’s NMITD AWT Journal MC1944
B. Create an XML Web Service with methods to calculate the area and
perimeter of a Rectangle. Consume this service through a Windows
client application.
Solution:-
Rectangle.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace AreaperimeterWebService {
/// <summary>
/// Summary description for rectangle
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class rectangle: System.Web.Services.WebService {
[WebMethod]
public int Area(int a, int b) {
return a * b;
}
[WebMethod]
public int Perimeter(int a, int b) {
return 2 * (a + b);
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
195 | P a g e
DES’s NMITD AWT Journal MC1944
namespace AreaperirectClient {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
}
}
}
196 | P a g e
DES’s NMITD AWT Journal MC1944
197 | P a g e
DES’s NMITD AWT Journal MC1944
C. Create an XML Web Service that returns all the branch details from
BranchTB. Write a Windows application that uses this service to
display branch details in a datagridview control.
Solution:-
Webapp1: WebServiceC
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebServiceC {
/// <summary>
/// Summary description for WebServicec
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebServicec: System.Web.Services.WebService {
[WebMethod]
public DataSet getBranchDetls() {
OleDbConnection con = new OleDbConnection(@
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\MCA\sem4\AWT\BranchTB.mdb");
OleDbDataAdapter da = new OleDbDataAdapter("Select * from
BranchTB", con);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
return ds;
}
}
}
198 | P a g e
DES’s NMITD AWT Journal MC1944
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClienC {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
Output:
199 | P a g e
DES’s NMITD AWT Journal MC1944
Access Database:
200 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:-
Form Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StringPractical1 {
public partial class Form2: Form {
public Form2() {
InitializeComponent();
}
Form2_Load(sender, e);
//this.branchTableTableAdapter3.Fill
//(this.branchTbDataSet3.BranchTable);
//comboBox1_SelectedIndexChanged(sender,e);
201 | P a g e
DES’s NMITD AWT Journal MC1944
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox2.Focus();
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Data;
namespace WebService {
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1: System.Web.Services.WebService {
[WebMethod]
public DataSet getBrancHDtls() {
202 | P a g e
DES’s NMITD AWT Journal MC1944
[WebMethod]
public DataSet getBranchDtlswithBrId(int c) {
OleDbConnection con = new OleDbConnection(@
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Xorro\Documents\Database3.mdb");
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * from Table1
where Br_Id=" + c, con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
[WebMethod]
public DataSet insertBankDtls(int c, string s, string s1) {
OleDbConnection con = new OleDbConnection(@
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Xorro\Documents\Database3.mdb");
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Insert into Table1 values('"
+ c + "','" + s + "','" + s1 + "')", con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
[WebMethod]
public DataSet getLoginDtls(string uname, string pwd) {
OleDbConnection con = new OleDbConnection(@
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Xorro\Documents\Database3.mdb");
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * from Table2
where Login_ID='" + uname + "' and Password='" + pwd + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
203 | P a g e
DES’s NMITD AWT Journal MC1944
Output:
204 | P a g e
DES’s NMITD AWT Journal MC1944
E. Create an XML Web Service that calculates the sum of two double
variables. Call this method and continue the execution of client
application while the sum is being calculated. (Asynchronous call to
Web Service)
Solution:-
Form Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StringPractical1 {
public partial class Form4: Form {
public Form4() {
InitializeComponent();
}
ServiceReference3.WebService2SoapClient cl = new
ServiceReference3.WebService2SoapClient();
IAsyncResult myIar;
}
}
}
205 | P a g e
DES’s NMITD AWT Journal MC1944
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService {
/// <summary>
/// Summary description for WebService2
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService2: System.Web.Services.WebService {
[WebMethod]
Output:
206 | P a g e
DES’s NMITD AWT Journal MC1944
207 | P a g e
DES’s NMITD AWT Journal MC1944
F. Create an XML Web Service that checks for Login credentials entered
by user with values in LoginTB. Write a Windows client that uses this
web service to Login.
Solution:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.OleDb;
namespace LoginserviceQ5 {
/// <summary>
/// Summary description for logincheck
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class logincheck: System.Web.Services.WebService {
[WebMethod]
public DataSet getlogindtls(string uname, string pwd) {
OleDbConnection con = new OleDbConnection(@
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\MCA\sem4\AWT\BranchTB.mdb");
OleDbDataAdapter da = new OleDbDataAdapter("select * from login where
Id='" + uname + "' and password='" + pwd + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
208 | P a g e
DES’s NMITD AWT Journal MC1944
using System.Threading.Tasks;
using System.Windows.Forms;
namespace loginchek {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
Output:
209 | P a g e
DES’s NMITD AWT Journal MC1944
Access database:
210 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:-
Service Code:
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1 {
// NOTE: You can use the "Rename" command on the "Refactor" menu to
change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1 {
/*[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
*/
[OperationContract]
int AddData(int a, int b);
[OperationContract]
int SubData(int a, int b);
[OperationContract]
int MulData(int a, int b);
[OperationContract]
int DivData(int a, int b);
211 | P a g e
DES’s NMITD AWT Journal MC1944
[DataMember]
public bool BoolValue {
get {
return boolValue;
}
set {
boolValue = value;
}
}
[DataMember]
public string StringValue {
get {
return stringValue;
}
set {
stringValue = value;
}
}
}
}
Service1.svc.cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1 {
// NOTE: You can use the "Rename" command on the "Refactor" menu to
change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please
select Service1.svc or Service1.svc.cs at the Solution Explorer and start
debugging.
public class Service1: IService1 {
/*public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
212 | P a g e
DES’s NMITD AWT Journal MC1944
}
}
Output:
Addition
Subtraction:
Multiply:
213 | P a g e
DES’s NMITD AWT Journal MC1944
Division:
214 | P a g e
DES’s NMITD AWT Journal MC1944
Solution:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3 {
public partial class CalculateDays: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
215 | P a g e
DES’s NMITD AWT Journal MC1944
return datetodays;
}
Output:
216 | P a g e