0% found this document useful (0 votes)
114 views50 pages

Awp New Compiled

The document contains code for several C# programs demonstrating basic concepts: 1. Four programs that get user input and perform operations: multiplying 4 numbers, splitting a string, collecting student data, generating a Fibonacci series. 2. A final program demonstrates: generating a Fibonacci series, checking for prime numbers, checking for vowels, using a foreach loop with arrays, and reversing a number and summing its digits.

Uploaded by

Yogesh Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views50 pages

Awp New Compiled

The document contains code for several C# programs demonstrating basic concepts: 1. Four programs that get user input and perform operations: multiplying 4 numbers, splitting a string, collecting student data, generating a Fibonacci series. 2. A final program demonstrates: generating a Fibonacci series, checking for prime numbers, checking for vowels, using a foreach loop with arrays, and reversing a number and summing its digits.

Uploaded by

Yogesh Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 50

Practical no 1A

Aim: create an application that obtained 4 integer value from the user and display the product.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace practicalno1A

{ class Program

{ static void Main(string[] args)

{ Console.WriteLine("Enter numbar 1");

int a=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter numbar 2");

int b= Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter numbar 3");

int c= Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter numbar 4");

int d= Convert.ToInt32(Console.ReadLine());

int p = a * b * c * d;

Console.WriteLine("Product of 4 number {0}",p);

Console.ReadKey(); }}}

PRACTICAL 1B

Aim= create an application to demonstrate string operation


using System;

using System.Collections.Generic;

using System.Linq;
using System.Text;

namespace practicalno1B

class Program

static void Main(string[] args)

string str1;

Console.Write("Enter String");

str1 = Console.ReadLine();

string[] words= str1.Split( ');

for (int i=0;i<words.Length;i++)

Console.WriteLine("\""+words[i]+"\"");

Console.ReadKey();

PRACTICAL 1C

Aim= create an application that receve student ID, strudent name,cource name,date of birth info from set of
student . the appshould also display the info of all students once the data is entered.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
namespace practicalno1B

class Program

struct Student

public string studid, name, cname;

public int day, month, year;

static void Main(string[] args)

Student[] s = new Student[2];

int i;

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

Console.Write("Enter Student ID:");

s[i].studid=Console.ReadLine();

Console.Write("Enter Student Name:");

s[i].name=Console.ReadLine();

Console.Write("Enter Student Cource name:");

s[i].cname=Console.ReadLine();

Console.Write("Enter Student Date Of Birth\n Enter Day(1-31):");

s[i].day=Convert.ToInt32(Console.ReadLine());

Console.Write("Enter Month(1-12):");

s[i].month= Convert.ToInt32(Console.ReadLine());

Console.Write("Enter year:");

s[i].month = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\n\nStudent's List\n");

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

Console.WriteLine("\nStudent ID:"+s[i].studid);
Console.WriteLine("\nStudent Name:"+s[i].name);

Console.WriteLine("\nCourse Name:" + s[i].cname);

Console.WriteLine("\nDate Of Birth(dd-mm-yyyy):" + s[i].day+"-"+s[i].month+"-"+s[i].year);

Console.ReadKey();

Console.WriteLine("\n\n\n"); }}}}

practical 1D

Aim: give an application todemonstarte

1= generate fibonari series

2= test for prime number

3= test for vowels

4= use for each loops

5= revers a number and find sum of digit

D(1) fibonaris series


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace practicalno1B

class Program

static void Main(string[] args)

int num1 = 0, num2 = 1, num3, num4, num, counter;

Console.Write("Up to how many number you want to fibonacci series:");

num = int.Parse(Console.ReadLine());

counter = 3;

Console.Write(num1 + "\t" + num2);

while (counter <= num)

num3 = num1 + num2;

if (counter >= num)

break;

Console.Write("\t" + num3);

num1 = num2;

num2 = num3;

counter++;

Console.ReadKey();

}}}}
D(2) prime number

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace practicalno1B

class Program

static void Main(string[] args)

int num, counter;

Console.Write("Enter number:");

num = int.Parse(Console.ReadLine());

counter = 3;

for(counter=2;counter<=num/2;counter++)

if ((num % counter) == 0)

break;

if(num==1)

Console.WriteLine(num+"\tis neither prime or nor composite");

else if(counter<(num/2))

Console.WriteLine(num+"\tis not prime number");

else

Console.WriteLine(num+"\tis prime number");

Console.ReadKey(); }}}
D(3) vowels

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace practicalno1B

class Program

static void Main(string[] args)

char ch;

Console.Write("Enter a character : ");

ch = (char)Console.Read();

switch (ch)

case a':

case A':

case e':

case E':

case i':

case I':

case o':

case O':

case u':
case U':

Console.WriteLine(ch + " is vowel");

break;

default:

Console.Write(ch + " is not vowel");

break;

Console.ReadKey();}}}

D(4) Reverse

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace practicalno1B

class Program

static void Main(string[] args)

int num, actualnumber, revnum = 0, digit, sumDigit = 0;

Console.Write("Enter number : ");

num = int.Parse(Console.ReadLine());

actualnumber = num;

while (num > 0)

digit = num % 10;


revnum = revnum * 10 + digit;

sumDigit = sumDigit + digit;

num = num / 10;

Console.WriteLine("Reverse of " + actualnumber + "=" + revnum);

Console.WriteLine("Sum of its digits : " + sumDigit);

Console.ReadKey(); } } }

Practical 1:
Practical_1(D) Create an application to demonstrate following operations
i. Generate Fibonacci series. ii. Test for prime numbers.
iii. Test for vowels. iv. Use of foreach loop with arrays
v. Reverse a number and find sum of digits of a number.

( i ): using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a=0, b=1, c,n;
Console.WriteLine("Enter Range:");
n=int.Parse(Console.ReadLine());
if (n >0)
{
Console.Write(a + " " + b + " ");
for (int i = 1; i <= n; i++)
{
c = a + b;
Console.Write(c + " ");
a = b;
b = c;
}
}
else
{
Console.WriteLine("Enter Valid number");
}

Console.ReadLine();
}
}
}

Output:

(ii): using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace prac1C_prime
{
class Program
{
static void Main(string[] args)
{
int num, c = 0;
Console.WriteLine("Enter a number:");
num=int.Parse(Console.ReadLine());
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
c++;
}
if (c == 2)
{
Console.WriteLine(num + " is prime");
}
else
{
Console.WriteLine(num + " is not prime");
}

Console.ReadLine();
}
}
}
Output:

1.
2.

(iii): using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace isvowel
{
class Program
{
static void Main(string[] args)
{
char[] v = { 'a', 'e', 'i', 'o', 'u'};
char ch;
Console.WriteLine("Enter a Character:");
ch =Convert.ToChar(Console.ReadLine().ToLower());
for(int i=0;i<5;i++)
{
if (ch == v[i])
{
Console.WriteLine(ch + " is Vowel");
break;
}
else if (i ==4)
{
Console.WriteLine(ch + " is not vowel");
}
}
Console.ReadLine();

}
}
}
output:
1.

2.

(iv)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace foreachdemon
{
class Program
{
static void Main(string[] args)
{
int[] ch = { 1, 2, 3, 4, 5 };
foreach (int c in ch)
{
Console.Write(c+" ");
}
Console.ReadLine();
}
}
}

Output:

(v) using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace reverse
{
class Program
{
static void Main(string[] args)
{
int n,num,rem, rev=0;
Console.WriteLine("Enter A number:");
n =int.Parse( Console.ReadLine());
num=n;
while (n > 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n = n / 10;
}
Console.WriteLine("Reverse of " + num + " is " + rev);
Console.WriteLine("Reverse of " + num + " is " + rev);

Console.ReadLine();

}
}
}

output:

Practical 2
Practial_2(a): Create simple application to perform following operations
i. Finding factorial Value ii. Money Conversion
iii. Quadratic Equation iv. Temperature Conversion .

(i): using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace factorial
{
class Program
{
static void Main(string[] args)
{
int n, fact=1;
Console.WriteLine("Enter a number: ");
n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
fact = fact * i;
}
Console.WriteLine("Factorial of " + n + " is " + fact);
Console.ReadLine();
}
}
}

output:

(ii):using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace monrey
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter 1 for converting doller to rupees:");
Console.WriteLine("enter 2 for converting euro to rupees:");
Console.WriteLine("enter 3 for converting pounds to rupees:");
int num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
Console.WriteLine("enter Doller amounnt:");
int dol = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter doller value:");
int v1 = Convert.ToInt32(Console.ReadLine());
int r1 = dol * v1;
Console.WriteLine(dol +" equals to " + r1 + " rupees");
break;
case 2:
Console.WriteLine("enter euro amounnt:");
int eur = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter euro value:");
int v2 = Convert.ToInt32(Console.ReadLine());
int r2 = eur * v2;
Console.WriteLine(eur + " equals to " + r2 + " rupees");
break;
case 3:
Console.WriteLine("enter Pound amounnt:");
int poun = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter Pound value:");
int v3 = Convert.ToInt32(Console.ReadLine());
int r3 = poun * v3;
Console.WriteLine(poun + " equals to " + r3 + " rupees");
break;
default:
Console.WriteLine("enter Proper choice:");
break;
}

Console.ReadLine();
}
}
}

output

(iii): using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter value for a");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter value for b");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter value for c");
int c = Convert.ToInt32(Console.ReadLine());
int d = (b * b) - (4 * a * c);
if (d > 0)
{
double r1 = (-b + Math.Sqrt(d)) / (2 * a);
double r2 = (-b - Math.Sqrt(d)) / (2 * a);
Console.WriteLine("r1:" + r1 + " r2:" + r2);
}
else if (d == 0)
{
double r3 = -b / (2 * a);
Console.WriteLine("root:" + r3);
}
else
{
Console.WriteLine("roots are imaginary");
}
Console.ReadLine();
}
}
}

Output:

(iv):using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tempconv
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter 1 for converting degree to farnheit:");
Console.WriteLine("enter 2 for converting farnheit to degree :");
int num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
Console.WriteLine("enter degree value:");
double d = Convert.ToInt32(Console.ReadLine());
double far = d * 9 / 5+ 32;
Console.WriteLine("value in degrees is:" + far);
break;

case 2:
Console.WriteLine("enter farnheit value:");
double f= Convert.ToInt32(Console.ReadLine());
double degree = (f - 32 )*5/ 9;
Console.WriteLine("value in farnheit is:" + degree);
break;
default:
Console.WriteLine("enter proper choice:");
break;
}
Console.ReadLine();
}
}
}

Output:

Practical_2(b):
Create simple application to demonstrate use of following concepts
i.Function Overloading- Write Function overloading and Print the code
ii. Inheritance (all types) - Write note on all inheritance and Print the code
iii.Constructor overloading- Write constructor overloading and Print the code
iv. Interfaces Write Interfaces and Print the code .

(i):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace functoverload
{
class Program
{
public int Area(int a, int b)
{
return a * b;
}
public int Area(int a)
{
return a * a;
}
public double Area(double a)
{
return 3.14 *a *a;
}
}

class Program1
{
static void Main(string[] args)
{
Program s = new Program();
int rect= s.Area(6, 7);
int square=s.Area(5);
double circ= s.Area(5.7);
Console.Write("Area of React=" + rect + "\n");
Console.Write("Area of SqUARE=" + square + "\n");
Console.Write("Area of React=" + circ + "\n");
Console.ReadLine();
}
}
}

Output:

(ii): Single inheritance


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace single
{
class Program
{
static void Main(string[] args)
{
Teacher d = new Teacher();
d.Teach();
Student s = new Student();
s.Learn();
s.Teach();
Console.ReadLine();
}
class Teacher
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
class Student : Teacher
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
}
Output:

multilevel inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace multilevel
{
class Mode
{
public void mode()
{
Console.WriteLine("There are Many Modes of Transport !!");
}
}
class vehicle : Mode
{
public void feature()
{
Console.WriteLine("They Mainly Help in Travelling !!");
}
}

class inheri : vehicle


{
public void Noise()
{
Console.WriteLine("All Vehicles Creates Noise !! ");
}
static void Main(string[] args)
{
inheri obj = new inheri();
obj.mode();
obj.feature();
obj.Noise();
Console.Read();
}
}
}

Output:

(iii): using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace constove
{
class BankAccount
{
private int cust_id;
private string cust_name;
private int bal;
public BankAccount()
{
cust_id = 1000;
cust_name = "Not Yet Specified";
bal = 0;
}
public BankAccount(int cust_id, string cust_name, int bal)
{
this.cust_id = cust_id;
this.cust_name = cust_name;
this.bal = bal;
}
public BankAccount(BankAccount obj)
{
cust_id = obj.cust_id;
cust_name = obj.cust_name;
bal = obj.bal;
}
public void ShowData()
{
Console.WriteLine("cust id = {0}, customer name = {1}, Bank Balance = {2}", cust_id,
cust_name, bal);
}
}
class Program
{
public static void Main(string[] args)
{
BankAccount a = new BankAccount(); // Invokes Default Constructor
BankAccount b = new BankAccount(102, "SAMKAM", 5000);// Invokes Parameterized Constructor
BankAccount c = new BankAccount(b);// Invokes Copy Constructor

a.ShowData();
b.ShowData();
c.ShowData();
Console.ReadLine();
}
}

Output:

Practical_2©:
Create simple application to demonstrate use of following concepts
i. Using Delegates and events Write what are Delegates and events and Print the code
ii. Exception handling Write Exception Handling and Print the code .

(i):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace delegate1
{
class Program
{
public delegate void Print(int value);

static void Main(string[] args)


{

Print printDel = PrintNumber;

printDel(100000);
printDel(200);

printDel = PrintMoney;

printDel(10000);
printDel(200);
Console.ReadLine();
}

public static void PrintNumber(int num)


{
Console.WriteLine("Number: {0}", num);
}

public static void PrintMoney(int money)


{
Console.WriteLine("Money: {0}", money);
}
}
}

output:

Practical 3A
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PracNo3A.Scripts
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button_click(object sender, EventArgs e)
{
if (TextBox1.Text.Equals("abc") && (TextBox2.Text.Equals("abc")))
{
Label1.Text = "Login Sussessful";
}
else
{
Label1.Text = "Login NotFiniteNumberException successful";
} } } }

Practical 3B

Button1 code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication5.Scripts
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }

protected void Button1_Click(object sender, EventArgs e)


{
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label1.Text = Calendar1.SelectedDate.ToString();
Label2.Text = "Todays Date" + Calendar1.TodaysDate.ToShortDateString();
Label3.Text = "Ganpati Vacation Start:09-02-2019";
TimeSpan d = new DateTime(2019, 9, 2) - DateTime.Now;
Label4.Text = "Days Remaining For Ganpati Vacation:" + d.Days.ToString();
TimeSpan d1 = new DateTime(2019, 12, 31) - DateTime.Now;
Label5.Text = "Days Remaining for New Year:" + d1.Days.ToString();
if(Calendar1.SelectedDate.ToShortDateString()=="09-02-2019")
Label3.Text ="<br> Ganpati Festival Start</br>";
if(Calendar1.SelectedDate.ToShortDateString()=="09-02-2019")
Label3.Text = "<br> Ganpati Festival Ends</br>";
}

Practical 3C
Xml FILE
<?xml version="1.0" encoding="utf-8" ?>
<studentdetail>
<student>
<sid>1</sid>
<sname>Reshma</sname>
<sclass>TYBSC(IT)</sclass>
</student>
<student>
<sid>2</sid>
<sname>Niraj</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>3</sid>
<sname>Abhay</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>4</sid>
<sname>nitin</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>

4B <Adverisements>
<Ad>
<ImageUrl>Koala.jpg</ImageUrl>
<NavigateUrl>http://www.1800flowers.com</NavigateUrl>
<AlternateText>
Order flower,roses,gift and more
</AlternateText>
<Imptessions>20</Imptessions>
<Keyword>flowers</Keyword>
</Ad>
<Ad>
<ImageUrl>Jellyfish.jpg</ImageUrl>
<NavigateUrl>http://www.babybouques.com.au</NavigateUrl>
<AlternateText>
Order gift
</AlternateText>
<Imptessions>20</Imptessions>
</Ad>
<Ad>
<ImageUrl>Penguins.jpg</ImageUrl>
<NavigateUrl>http://www.1700moscow.com.au</NavigateUrl>
<AlternateText>
Send flower to USA
</AlternateText>
<Imptessions>20</Imptessions>
</Ad>
<Ad>
<ImageUrl>Hydrangeas.jpg</ImageUrl>
<NavigateUrl>http://www.flower2.com.au</NavigateUrl>
<AlternateText>
Send gift to Mumbai
</AlternateText>
<Imptessions>20</Imptessions>
</Ad>
</Adverisements>

5A <studendeail>
<student>
<Alli>1</Alli>
<sname>Sahil</sname>
<sclass>TYIT</sclass>
</student>
<student>
<Alli>2</Alli>
<sname>Vibhuti</sname>
<sclass>TYCS</sclass>
</student>
<student>
<Alli>3</Alli>
<sname>Jay</sname>
<sclass>TYIT</sclass>
</student>
<student>
<Alli>4</Alli>
<sname>Rahul</sname>
<sclass>TYCS</sclass>
</student>

OUTPUT
3A

5A

4A
3B
3C

4B
Practical 5(b)
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> </head>
<body>Hello<br />
<form id="form1" runat="server"> <div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder> </div> </form> </body> </html>

Default.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" Theme="SkinFile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:Label
ID="Label1" runat="server" Text="Advanced web programming"></asp:Label> <br /> <asp:Label
ID="Label2" runat="server" Text="TYBScIT"></asp:Label> <br />
<asp:Label ID="Label3" runat="server" Text="Sem V"></asp:Label> <br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</asp:Content>
Stylesheet.css:
body { background-color:Red;
font-family:Times New Roman;
font-size:25; }

Default.aspx.cs:
using System; using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
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) {
Label4.Text = "Patkar College"; } }
Skinfile:<asp:Label runat="server" ForeColor="green" Font-Names="Verdana"/> <asp:Button
runat="server" Borderstyle="solid" Borderwidth="5px" />
5B

Practical 6 (a):

1. Create a webpage with one Button, one Multiline TextBox and one list box with setting TextMode
Property of text box to Multiline as shown below.

2. Write the Database related code in code behind C# file as given below.
3 Add this string to configuration file (web.config) as given below. Web.confing
<configuration> <system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" /> </system.web>
<connectionStrings> <add name="connStr"
connectionString="DataSource=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\tushars\Documents\
Visual Studio
2015\WebSites\Workshop\App_Data\Database.mdf';Integrated Security=True" /> </connectionStrings>
</configuration>
4. Now use the following code C# in Default.aspx.cs (Note : First write following using statements at the top
of file
using System; using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using
System.Data; using System.Data.SqlClient; using System.Configuration;
public partial class DataBinding : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
} protected void Button1_Click(object sender, EventArgs e)
{ string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; SqlConnection con = new
SqlConnection(connStr); con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text, con);
SqlDataReader reader = cmd.ExecuteReader(); ListBox1.Items.Clear(); while (reader.Read()) {
for (int i = 0; i < reader.FieldCount - 1; i++) { ListBox1.Items.Add(reader[i].ToString()); } }
reader.Close(); con.Close(); } }
Output:

Practical 6 (b):
Add the following code on Button click event in C# Code behind file.
protected void Button1_Click(object sender, EventArgs e)
{ string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; SqlConnection con = new
SqlConnection(connStr); SqlCommand cmd = new SqlCommand("Select City, State from Customer", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
Label1.Text += reader["City"].ToString() + " " + reader["State"].ToString() + "<br>"; } reader.Close();
con.Close(); }

Output:

Practical 6 (c):
1. Drag the Datalist control to our web page form toolbox->Data-> Datalist.
2. Then select Choose Data Source Option and select <New Data Source>.

3. Now Select SQL Database from options and Click Ok button.


4. In next window click on New Connection button.
5. In add connection window Select the available SQL Server Name 6. Keep the Authentication as
Windows Authentication.
7. After that select Attach a Database file radio button. Here we have to select the database that we have
created in our application. (Usually it will be in Documents folder under Visual Studio 2015/ Websites).
8. After selection of Database file. We can also Test the connection.
9. Then Click on OK button.

10. Once the Connection is made then click on Next button from Data Source Wizard.
11. Then wizard ask for saving the connection string in configuration file. If you already stored it
web.config file then uncheck check box, if you haven’t, then select the checkbook. Then click on next
button.
12. The next screen gives option to configure the select statement. Here we can choose the table as well as
configure the select statement as we need to display the data on web page.

13. In next screen we can test our query to check the output. Then Click on finish.
After successful steps form the Datalist controls option wizard our web page design and output will look like
following.
Practical 7 (a)

Code of C# Code behind file


using System; usingSystem.Collections.Generic; using System.Linq; using System.Web; using
System.Web.UI; using System.Data;
using System.Data.SqlClient; using System.Configuration;
using System.Web.UI.WebControls;
public partial class DBDropDown : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (IsPostBack == false) { string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select Distinct City from Customer", con); con.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader; DropDownList1.DataTextField = "City";
DropDownList1.DataBind(); reader.Close(); con.Close(); } }
protected void Button1_Click(object sender, EventArgs e) {
Label1.Text = "The You Have Selected : " + DropDownList1.SelectedValue; } }

Output:

Practical 7 (b):

Code of C# Code behind file using System;


using System.Collections.Generic; using System.Linq; using System.Web;using System.Web.UI; using
System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using
System.Configuration;
public partial class PostalCodeByCity : System.Web.UI.Page {
protected void Button1_Click(object sender, EventArgs e) {
Label1.Text = ListBox1.SelectedValue; }
protected void Page_Load(object sender, EventArgs e)
{ if (IsPostBack == false) { string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select Distinct POSTAL_CODE from Customer", con);
con.Open(); SqlDataReader reader = cmd.ExecuteReader(); ListBox1.DataSource = reader;
ListBox1.DataTextField = "City"; ListBox1.DataValueField = "POSTAL_CODE";
ListBox1.DataBind(); reader.Close(); con.Close(); } } }
Output:
Practical 7 (c):

Code of C# Code behind file using System;


using System.Collections.Generic; using System.Linq; using System.Web;
using System.Web.UI; using System.Web.UI.WebControls;
using System.Data; using System.Data.SqlClient; using System.Configuration;
public partial class ExecuteNonQuery : System.Web.UI.Page {
protected void Button1_Click(object sender, EventArgs e) {
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; SqlConnection
con = new SqlConnection(connStr);
string InsertQuery = "insert into BRANCH values(@ADDRESS, @CITY, @NAME, @STATE,
@ZIP_CODE)";
SqlCommand cmd = new SqlCommand(InsertQuery, con); cmd.Parameters.AddWithValue("@ADDRESS",
TextBox1.Text); cmd.Parameters.AddWithValue("@CITY", TextBox2.Text);
cmd.Parameters.AddWithValue("@NAME", TextBox3.Text); cmd.Parameters.AddWithValue("@STATE",
TextBox4.Text);
cmd.Parameters.AddWithValue("@ZIP_CODE", TextBox5.Text); con.Open();
cmd.ExecuteNonQuery(); Label1.Text = "Record Inserted Successfuly."; con.Close(); } protected
void Button2_Click(object sender, EventArgs e) {
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; SqlConnection
con = new SqlConnection(connStr);
string InsertQuery = "delete from branch where NAME=@NAME"; SqlCommand cmd = new
SqlCommand(InsertQuery, con); cmd.Parameters.AddWithValue("@NAME", TextBox1.Text); con.Open(
);
cmd.ExecuteNonQuery( ); Label1.Text = "Record Deleted Successfuly."; con.Close( ); }
}
Practical 8
Practical 8(a):

default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"/> <body> <form id="form1" runat="server">
<asp:DataList ID="DataList1" runat="server" DataKeyField="id" DataSourceID="SqlDataSource4">
<ItemTemplate>
id: <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' /> <br />
fname: <asp:Label ID="fnameLabel" runat="server" Text='<%# Eval("fname") %>' /> <br />
lname: <asp:Label ID="lnameLabel" runat="server" Text='<%# Eval("lname") %>' /> <br />
city: <asp:Label ID="cityLabel" runat="server" Text='<%# Eval("city") %>' /> <br /> country: <asp:Label
ID="countryLabel" runat="server" Text='<%# Eval("country") %>' /> <br /> phoneno:
<asp:Label ID="phonenoLabel" runat="server" Text='<%# Eval("phoneno") %>' /> <br /> <br />
</ItemTemplate> </asp:DataList>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$
ConnectionStrings:DatabaseConnectionString3 %>"
SelectCommand="SELECT * FROM [customer]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
SelectCommand="SELECT * FROM [cust]"></asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource2" Height="50px"
Width="125px" AutoGenerateRows="False" DataKeyNames="id"> <Fields>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="lname" SortExpression="lname" />
<asp:BoundField DataField="city" HeaderText="city" SortExpression="city" />
<asp:BoundField DataField="country" HeaderText="country"
SortExpression="country" />
<asp:BoundField DataField="phoneno" HeaderText="phoneno"
SortExpression="phoneno" /> </Fields> </asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString2 %>"
SelectCommand="SELECT * FROM [customer]"></asp:SqlDataSource> <asp:FormView ID="FormView1"
runat="server" DataSourceID="SqlDataSource6" DataKeyNames="id"> <EditItemTemplate>
id: <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' /><br />
fname: <asp:TextBox ID="fnameTextBox" runat="server" Text='<%# Bind("fname") %>' /> <br />
lname: <asp:TextBox ID="lnameTextBox" runat="server" Text='<%# Bind("lname") %>' />
<br />
city: <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>' /> <br />
country: <asp:TextBox ID="countryTextBox" runat="server" Text='<%# Bind("country") %>' />
<br />
phoneno: <asp:TextBox ID="phonenoTextBox" runat="server" Text='<%# Bind("phoneno") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />&nbsp;
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate> <InsertItemTemplate>
id: <asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' />
<br /> fname:
<asp:TextBox ID="fnameTextBox" runat="server" Text='<%# Bind("fname") %>' /> <br /> lname:
<asp:TextBox ID="lnameTextBox" runat="server" Text='<%# Bind("lname") %>' /> <br /> city:
<asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>' />
<br /> country: <asp:TextBox ID="countryTextBox" runat="server" Text='<%# Bind("country") %>' />
<br /> phoneno:
<asp:TextBox ID="phonenoTextBox" runat="server" Text='<%# Bind("phoneno") %>' /> <br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" /> &nbsp;
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate> <ItemTemplate>
id: <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
<br /> fname:
<asp:Label ID="fnameLabel" runat="server" Text='<%# Bind("fname") %>' /> <br /> lname:
<asp:Label ID="lnameLabel" runat="server" Text='<%# Bind("lname") %>' />
<br /> city:
<asp:Label ID="cityLabel" runat="server" Text='<%# Bind("city") %>' /> <br />
country: <asp:Label ID="countryLabel" runat="server" Text='<%# Bind("country") %>' />
<br />
phoneno: <asp:Label ID="phonenoLabel" runat="server" Text='<%# Bind("phoneno") %>' /> <br />
</ItemTemplate> </asp:FormView>8A
Practical no 9 A
Design:

XMLFile2.xml
<?xml version="1.0" encoding="utf-8" ?> <student>
<name>xyz</name> <roll>1</roll> </student>
XMLFile.xml Keep this file is empty for writing purpose.
Source Code:
using System; using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Xml;
public partial class _Default : System.Web.UI.Page {
protected void Button1_Click(object sender, EventArgs e) {
XmlReader red = XmlReader.Create(@"C:\Users\lenovo\Documents\Visual Studio
2010\WebSites\WebSite6\XMLFile2.xml");
while (red.Read()) { if (red.NodeType.Equals(XmlNodeType.Element))
{ string s = Label1.Text + " "; Label1.Text = s+ red.Name; } }
red.Close(); } protected void Button2_Click(object sender, EventArgs e)
{ XmlWriterSettings set = new XmlWriterSettings(); set.Indent = true;
XmlWriter wr = XmlWriter.Create(@"C:\Users\lenovo\Documents\Visual Studio
2010\WebSites\WebSite6\XMLFile.xml", set);
wr.WriteStartDocument(); wr.WriteComment("example of write to xml document");
wr.WriteStartElement("student"); wr.WriteEndElement(); } }
Output :

This data is from


XMLFile2.xml

Prractical 9 B
Step 1: Choose Website -> ASP.NET Configuration to open the Web Application Administration Tool.
Step 2: Click on the Security tab.

Step 3: Select 'From the Internet' radio button option after clicking on ‘Select authentication type’ for form base
authentication and click on Done button.
Step 4: Go to the security tab again and click on ‘Enable role’ option for enabling roles for user.

Step5: To Create Roles click on ‘Create or Manage role’ option.

Step6: create role as ‘MANAGER’ as shown follows:


Step7: Click on 'Create Users' link to create some users. If you already had created roles, you could assign roles
to the user, right at this stage.

Step8: Create a web site and add the following pages:


 Welcome.aspx
 Login.aspx CreateAccount.aspx
 PasswordRecovery.aspx
 ChangePassword.aspx

Step9: Place a LoginStatus control on the Welcome.aspx from the login section of the toolbox. It has two
templates: LoggedIn and LoggedOut.
Step10: Place a LoginView control from the toolbox below the LoginStatus control.

Step11: The users for the application are created by the developer. You might want to allow a visitor to create a
user account. For this, add a link beneath the LoginView control, which should link to the CreateAccount.aspx
page.
Step12 : Place a CreateUserWizard control on the create account page. Set the ContinueDestinationPageUrl
property of this control to Welcome.aspx.

Step13 : Place a Login control on the Login page. The LoginStatus control automatically links to the Login.aspx.
To change this default, make the following changes in the web.config file.
For example, if you want to name your log in page as signup.aspx, add the following lines to the <authentication>
section of the web.config:
<configuration> <system.web> <authentication mode="Forms">
<forms loginUrl ="signup.aspx" defaultUrl = “Welcome.aspx” />
</authentication> </system.web> </configuration>
Step14 : Sometime user forget password. The PasswordRecovery control helps the user gain access to the
account. Select the Login control. Open its smart tag and click 'Convert to Template'. Customize the UI of the
control to place a hyperlink control under the login button, which should link to the PassWordRecovery.aspx

Step 15 : Place a PasswordRecovery control on the password recovery page. This control needs an email server
to send the passwords to the users.

Step16 : Create a link to the ChangePassword.aspx page in the LoggedIn template of the LoginView control in
Welcome.aspx.

Step17 : Place a ChangePassword control on the change password page. This control also has two views.

Now run the application and observe different security operations.


PROGRAM 2:
AIM: To change the authentication mode to Windows for a web page of Employee
CODE:
<system.web> <authentication mode=”Windows”>
<forms loginUrl=”~/”Practical10/Employee.aspx”>
</authentication> </system.web >
Steps for changing the authentication mode:
1. Open the website created for displaying the Employee data
2. From the solution Explorer window open the web.config file
3 .In the web.config file search the <system.web> xml tag and in <system.web> xml tag go to authentication tag
4. Change the authentication mode to windows as given above.
PROGRAM 3:
<system.web> <authentication> <allow users=”MANAGER”/>
<deny users =” *”/> </authentication> </system.web>
Steps for changing the authorization:
1. Open the website created for displaying the employee data.
2. Open the web.config file from solution explorer.
3. In the Web.config file search the <system.web> xml tag and in <system.web> xml tag go to authentication tag
4. Change the coding in the tag as given above.
PROGRAM 4:

Source Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
</head> <body> <form id="form1" runat="server"> <div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager> <br /> <br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="margin-left: 14px" Text="SHOW TIME" /> <br /> <br />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>PLEASEWAIT FOR SOMETIME </ProgressTemplate>
</asp:UpdateProgress> </div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
</asp:UpdatePanel> </form> </body> </html>
Coding:
using System; using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
System.Threading.Thread.Sleep(2000); }
protected void Button1_Click(object sender, EventArgs e) {
TextBox1.Text = DateTime.Now.ToLongTimeString(); } }
OUTPUT :

Practiccal nono 9 B
Program 1: Program to create and use DLL.
using System; using System.Collections.Generic;
using System.Linq; using System.Text;
namespace ClassLibrary2 { public class Class1 {
public int add(int a, int b) { int c=a+b; return c; } } }

CODE :
using System; using System.Collections.Generic; using System.Linq;
using System.Text; using ClassLibrary;
namespace ConsoleApplication1 { class Program {
static void Main(string[] args) { ClassLibrary.Class1 c = new Class1();
int t=c.add(1, 2); Console.WriteLine("addition={0}",t); Console.ReadKey(); } } }
OUTPUT :
Practical No: 10
Perform logistic regression on the given data warehouse data.

The in-built data set "mtcars" describes different models of a car with their various engine specifications. In
"mtcars" data set, the transmission mode (automatic or manual) is described by the column am which is a binary
value (0 or 1). We can create a logistic regression model between the columns "am" and 3 other columns - hp, wt
and cyl.

Create Regression Model


We use the glm() function to create the regression model and get its summary for analysis.
In the summary as the p-value in the last column is more than 0.05 for the variables "cyl"
and "hp", we consider them to be insignificant in contributing to the value of the variable
"am". Only weight (wt) impacts the "am" value in this regression model.

You might also like