0% found this document useful (0 votes)
984 views48 pages

CBT Manual N-Scheme

Uploaded by

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

CBT Manual N-Scheme

Uploaded by

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

N-SCHEME

DEPARTMENT OF COMPUTER ENGINEERING

III-YEAR / V- SEM

4052561

COMPONENT BASED TECHNOLOGY

PRACTICAL
PART-A

Ex no:1 CASE CHECKING

Date:

Aim:

To Accept a Character from console and check the case of the character

Procedure:

1. Open Microsoft Visual studio File -> New -> Project

2. Select project type as Visual c# -> windows and template type as Console application, then
click ok.

Program

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
char c;
Console.WriteLine("enter character");
c = (char)Console.Read();
if (char.IsLower(c))
{
Console.WriteLine("lowercase");
}
else if (char.IsUpper(c))
{
Console.WriteLine("uppercase");
}
else
Console.WriteLine("others");
}
}
}
OUTPUT

Result:

Thus the program for accepting a character from console and checking case of the Character was
completed and output verified successfully.
Ex no:2 VOWEL CHECKING

Date:

Aim:

To Write a program to accept any character from keyboard and display whether vowel or not.

Procedure:

1. Open Microsoft Visual studio File ->New->Project

2. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK and Design a Form as shown in Figure

Program

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 vowel_check
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{

}
private void button1_Click(object sender, EventArgs e)
{
String c,d;
c = textBox1.Text;
d = c.ToUpper();
if ((d== "A")||(d== "E")||(d== "I")||(d== "O")||(d == "U"))
textBox2.Text = "VOWEL";
else
textBox2.Text = "NOT VOWEL";
}
}
}

Output
Result:

Thus the C# program for accepting any character from keyboard and display whether vowel or
not was completed and output verified successfully.
Ex no :3 CALCULATOR

Date :

Aim:

To Write a program to implement a calculator with memory and recall operations.

Procedure:

1. Open Microsoft Visual studio File ->New->Project

2. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

3. Design a form as shown in figure

Program

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 calc1
{
public partial class Form1 : Form
{
int p;
string m,op;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
textBox1.Text = String.Empty;
}

private void button2_Click(object sender, EventArgs e)


{
m = textBox1.Text;
textBox1.Text = String.Empty;
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Text = m;
}

private void button4_Click(object sender, EventArgs e)


{
textBox1.AppendText("1");
}

private void button5_Click(object sender, EventArgs e)


{
textBox1.AppendText("2");
}

private void button6_Click(object sender, EventArgs e)


{
textBox1.AppendText("3");
}

private void button7_Click(object sender, EventArgs e)


{
textBox1.AppendText("4");
}

private void button8_Click(object sender, EventArgs e)


{
textBox1.AppendText("5");
}

private void button9_Click(object sender, EventArgs e)


{
textBox1.AppendText("6");
}

private void button10_Click(object sender, EventArgs e)


{
textBox1.AppendText("7");

private void button11_Click(object sender, EventArgs e)


{
textBox1.AppendText("8");
}

private void button12_Click(object sender, EventArgs e)


{
textBox1.AppendText("9");
}

private void button13_Click(object sender, EventArgs e)


{
textBox1.AppendText("0");
}

private void button14_Click(object sender, EventArgs e)


{
p = Convert.ToInt32(textBox1.Text);
op = "+";
textBox1.Text = String.Empty;
}

private void button15_Click(object sender, EventArgs e)


{
p = Convert.ToInt32(textBox1.Text);
op = "-";
textBox1.Text = String.Empty;
}

private void button16_Click(object sender, EventArgs e)


{
p = Convert.ToInt32(textBox1.Text);
op = "*";
textBox1.Text = String.Empty;
}
private void button17_Click(object sender, EventArgs e)
{
p = Convert.ToInt32(textBox1.Text);
op = "/";
textBox1.Text = String.Empty;

private void button18_Click(object sender, EventArgs e)


{
switch (op)
{
case "+":
p = p + Convert.ToInt32(textBox1.Text);
textBox1.Text = Convert.ToString(p);
break;
case "-":
p = p - Convert.ToInt32(textBox1.Text);
textBox1.Text = Convert.ToString(p);
break;
case "*":
p = p * Convert.ToInt32(textBox1.Text);
textBox1.Text = Convert.ToString(p);
break;
case "/":
p = p / Convert.ToInt32(textBox1.Text);
textBox1.Text = Convert.ToString(p);
break;
}
}
}
}
OUTPUT

Result:

Thus the C# program for implementing calculator was completed and output verified
successfully.
Ex no :4 CALENDAR APPLICATION

Date :

Aim:

Develop a form in to pick a date from Calendar control and display the day, month, year details
in separate text boxes.

Procedure:

1. Open Microsoft Visual studio File ->New->Project

2. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

3. Design a form as shown in figure

Program

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 calaender
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
int a, b, c;
a = dateTimePicker1.Value.Day;
b = dateTimePicker1.Value.Month;
c = dateTimePicker1.Value.Year;
textBox1.Text = a.ToString();
textBox2.Text = b.ToString();
textBox3.Text = c.ToString();
}
}
}

OUTPUT

Result:

Thus the C# program for implementing calculator was completed and output verified
successfully.
Ex no : 5 FILE AND FOLDER CONTROL

Date :

Aim:

Develop a application using the File and Directory controls to implement a common dialog box

Procedure:

1. Open Microsoft Visual studio File ->New->Project

2. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

3. Design a form as shown in figure

Program

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 file_and_folder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{

private void label2_Click(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
if (radioButton1.Checked)
{
folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
else
{
openFileDialog1.ShowDialog();
textBox2.Text = openFileDialog1.FileName;
}
}
}
}
OUTPUT

Result:

Thus the C# program for developing an application using the File and Directory controls to
implement a common dialog box was completed and output verified successfully.
Ex.No : 6 DATABASE CREATION USING ADO.NET

Date :

Aim:

Develop a Database application to store the details of students using ADO.NET.

Procedure:

1.Open Microsoft SQL Server and Create a table stud in student database by using the following
commands

create database student


use student
create table stud(regno varchar(10), sname varchar(15), dept varchar(15))

2. Open Microsoft Visual studio File ->New->Project

3. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

4. Design a form as shown in figure

5. Enter the code in relevant controls

Program

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.SqlClient;
namespace EX6
{
public partial class Form1 : Form
{
public SqlConnection con;
public SqlCommand com;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
MessageBox.Show("please fill all the Details");
else
com.CommandText = "insert into stud values('" + textBox1.Text + "', '" + textBox2.Text
+ "','" + textBox3.Text + "')";
com.ExecuteNonQuery();
MessageBox.Show("1 record is stored successfully");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
}

private void Form1_Load(object sender, EventArgs e)


{
con = new SqlConnection("Data Source=CT-37\\SQLEXPRESS; Initial
Catalog=student1;Integrated Security=True");
com = new SqlCommand();
com.Connection = con;
con.Open();
}
}
}

6. For Database connectivity click data menu -> Add new DataSource->New Connection-
>select Server name and database name.
7. Check Test Connection and copy the link. Assign it in the Sql Connection.
8. Run the Program.
OUTPUT:

Result:

Thus the C# program for Database application to store details of students using ADO.NET was
completed and output verified successfully
Ex.No : 7 ASP.NET PAGE CREATION

Date :

Aim:

Create a simple ASP.NET page to output text with a form, two HTML text boxes, an
HTML button, and an HTML<span> element. Create an event procedure for the button.

Procedure:

1. Open Microsoft Visual studio File ->New->Web site

2. Select templates as Visual c# -> ASP.NET Empty web site, then click OK.

3.solution explorer ->website1->add->add new item->visual c#->web form-> click add.

4. Design a form as shown in figure

Program

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"


Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
span {
color: brown;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>

<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="CLICK"
Width="103px" />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<br />
<br />
<br />

</div>
</form>
</body>
</html>

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)
{
Label1.Text = TextBox1.Text;
Label2.Text = TextBox2.Text;
}
}

5.Run the web application.

Output:

Result:

Thus the C# program for creating ASP.NET page, web based application was completed and
output verified successfully.
PART-B

Ex.No : 8 TEXT EDITOR CREATION

Date :

Aim:

Develop a menu based application to implement a text editor with cut, copy, paste, save and
close operations with accessing key and shortcut keys.

Procedure:

1. Open Microsoft Visual studio File ->New->Project

2. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

3. Design a form as shown in figure

Program

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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)


{
label1.Visible = true;
textBox1.Visible = true;
button1.Visible = true;
}

private void closeToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Clear();
}

private void cutToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Cut();
}

private void copyToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Copy();
}

private void pastToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Paste();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void button1_Click(object sender, EventArgs e)


{
richTextBox1.SaveFile("textBox1.Text");
label1.Visible = false;
textBox1.Visible = false;
button1.Visible = false;
}
}
}

OUTPUT:

Result:

Thus the C# program for Developing Menu based application was completed and output verified
successfully.
Ex.No : 9 QUIZ CREATION

Date :

Aim:

Develop a Application to Perform timer based Quiz of 5 Questions.

Procedure:

1. Open Microsoft Visual studio File ->New->Project

2. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK. 3. Design a form as shown in figure

Program:

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 Quiz
{
public partial class Form1 : Form
{
String[,] Quest = new String[6, 5];
String[,] Answer = new String[6, 2];
int i = -1;
public Form1()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)


{
i = i + 1;
if (i == 5)
{
timer1.Enabled = false;
button1.Enabled = true;
}
else
{
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
textBox1.Text = Quest[i, 0];
radioButton1.Text = Quest[i, 1];
radioButton2.Text = Quest[i, 2];
radioButton3.Text = Quest[i, 3];
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)


{
Answer[i, 1] = radioButton1.Text;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)


{
Answer[i, 1] = radioButton2.Text;
}

private void radioButton3_CheckedChanged(object sender, EventArgs e)


{
Answer[i, 1] = radioButton3.Text;
}

private void button1_Click(object sender, EventArgs e)


{
int j, count = 0;
for (j = 0; j < 5; j++)
{
if (Answer[j, 0] == Answer[j, 1])
{
count += 1;
}
}
MessageBox.Show(String.Format("You Have Scored {0} marks", count));
}

private void Form1_Load_1(object sender, EventArgs e)


{
Quest[0, 0] = "In ____ India won cricket world cup";
Quest[0, 1] = "1973";
Quest[0, 2] = "1983";
Quest[0, 3] = "1987";
Quest[1, 0] = "Scanner is a ______ device";
Quest[1, 1] = "Input";
Quest[1, 2] = "Output";
Quest[1, 3] = "I/O";
Quest[2, 0] = "which one of the follwing is browser";
Quest[2, 1] = "Visual Basic";
Quest[2, 2] = "Java";
Quest[2, 3] = "Internet Explorer";
Quest[3, 0] = "______ was not a chief minister";
Quest[3, 1] = "Kamarajar";
Quest[3, 2] = "Sivaji";
Quest[3, 3] = "MGR";
Quest[4, 0] = "______ is not a memory storage";
Quest[4, 1] = "pendrive";
Quest[4, 2] = "Hard disc";
Quest[4, 3] = "SMPS";
Answer[0, 0] = "1983";
Answer[1, 0] = "Input";
Answer[2, 0] = "Internet Explorer";
Answer[3, 0] = "Sivaji";
Answer[4, 0] = "SMPS";
timer1.Enabled = true;
button1.Enabled = false;
}

}
}
Output:

Result:

Thus the C# program for developing an application to Perform timer based Quiz of 5 Questions
was completed and output verified successfully.
Ex.No : 10 DATABASE UPDATION USING ADO.NET

Date :

Aim:

Develop a application using ADO.NET to insert, modify, update and delete operations.

Procedure:

1. Open Microsoft SQL Server and Create a table stud in student database by using the following
commands

create database student 2

use student 2

create table stud(regno varchar(10), sname varchar(15), dept varchar(15)) insert into stud
values(‘115526’,’Robert’,’Civil’)

2. Open Microsoft Visual studio File ->New->Project

3. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

4. Design a form as shown in figure


Program:

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.SqlClient;
namespace EX10
{
public partial class Form1 : Form
{
public SqlConnection con;
public SqlCommand com;
public SqlDataReader rd;
public Form1()
{
InitializeComponent();
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
comboBox1.Visible = false;
button1.Enabled = true;
textBox1.Visible = true;
button2.Enabled = false;
button3.Enabled = false;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)


{
comboBox1.Items.Clear();
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
comboBox1.Visible = true;
textBox1.Visible = false;
com.CommandText = "select * from stud";
rd = com.ExecuteReader();
while (rd.Read())
{
comboBox1.Items.Add(rd.GetString(0));
}
rd.Close();
}

private void button1_Click(object sender, EventArgs e)


{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
MessageBox.Show("please fill all the Details");
else
com.CommandText = "insert into stud values('" + textBox1.Text + "', '"+ textBox2.Text + "', '"
+ textBox3.Text + "')";
com.ExecuteNonQuery();
MessageBox.Show("record inserted");
}

private void button2_Click(object sender, EventArgs e)


{
com.CommandText = "delete from stud where regno='" + comboBox1.SelectedItem +
"'";
rd = com.ExecuteReader();
comboBox1.Items.Remove(comboBox1.SelectedItem);
textBox2.Clear();
textBox3.Clear();
MessageBox.Show("record deleted");
}

private void button3_Click(object sender, EventArgs e)


{
com.CommandText = "update stud set sname='" + textBox2.Text + "',dept='" +
textBox3.Text + "' where regno='" + comboBox1.SelectedItem +"'";
com.ExecuteNonQuery();
MessageBox.Show("record updated");
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
com.CommandText = "select * from stud where regno='" + comboBox1.SelectedItem +
"'";
rd = com.ExecuteReader();
if (rd.Read())
{
textBox2.Text = rd.GetString(1);
textBox3.Text = rd.GetString(2);
}
rd.Close();
}

private void Form1_Load(object sender, EventArgs e)


{
con = new SqlConnection("Data Source=CT-37\\SQLEXPRESS; Initial
Catalog=student1;Integrated Security=True");
com = new SqlCommand();
com.Connection = con;
con.Open();

}
}
}

Output:
Result:

Thus the C# program for Database application to insert, modify, update and delete operations
using ADO.NET was completed and output verified successfully.
Ex.No : 11 DATABASE UPDATION USING DATAGRID

Date :

Aim:

Develop a application using Datagrid to add, edit and modify records.

Procedure:

1. Open Microsoft SQL Server and Create a table stud in student database by using the following
commands

create database student3

use student 3

create table stud1(regno varchar(10), sname varchar(15), address varchar(15),dept varchar(15))

2. Open Microsoft Visual studio File ->New->Project

3. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

4. Design a form as shown in figure.


Program:

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.SqlClient;
namespace EX11
{
public partial class Form1 : Form
{
public SqlConnection con=new SqlConnection("Data Source=CT-
37\\SQLEXPRESS;Initial Catalog=student3;Integrated Security=True");
public SqlCommand com=new SqlCommand();
public SqlDataReader rd;
int n;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
com.Connection = con;
con.Open();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs


e)
{
com.CommandText = "update stud1 set sname= '" +
dataGridView1.CurrentRow.Cells[1].Value + "',address='" +
dataGridView1.CurrentRow.Cells[2].Value + "',dept = '"+
dataGridView1.CurrentRow.Cells[2].Value + "'where regno= '" +
dataGridView1.CurrentRow.Cells[0].Value + "'";
com.ExecuteNonQuery();
MessageBox.Show("One record updated...");
SqlDataAdapter da1 = new SqlDataAdapter("select * from stud1", con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "stud1");
dataGridView1.DataSource = ds1.Tables["stud1"];
}

private void button1_Click(object sender, EventArgs e)


{
dataGridView1.Visible = false;
com.CommandText = "select count(*) from stud1";
n = (Int32)com.ExecuteScalar();
textBox1.Text = "S000" + n + 1;
com.CommandText = "insert into stud1 values('"+ textBox1.Text +"','"+ textBox2.Text + "','"+
textBox3.Text +"','"+ textBox4.Text +"')";
com.ExecuteNonQuery();
MessageBox.Show("One record inserted");
}

private void button2_Click(object sender, EventArgs e)


{
dataGridView1.Visible = true;
SqlDataAdapter da = new SqlDataAdapter("select * from stud1", con);
DataSet ds = new DataSet();
da.Fill(ds, "stud1");
dataGridView1.DataSource = ds.Tables["stud1"];
}
}
}

Output:
Result:

Thus the application using DataGrid to add, edit and modify records was completed and
output verified successfully.
Ex.No : 12 REQUIRED FIELD VALIDATOR AND RANGE VALIDATOR

Date :

Aim:

Develop a web application to input data through a web form to a database and validate the
data. use the required filed validator and range validator controls.

Procedure:

1. Open Microsoft Visual studio File ->New->Web site

2. Select templates as Visual c# -> ASP.NET Empty web site, then click OK.

3.solution explorer ->website7->add->add new item->visual c#->web form-> click add.

4. Design a form as shown in figure

5. solution explorer ->website1->add->add new item->visual c#->SQL SERVER DATABASE -


> click add.

6.Server explorer ->database1.mdf->tables->right click->create table column name


varchar(10),pwd varchar(10),age varchar(10) ->go to T-SQL table name give stud1-> click
update->click update database

7. solution explorer ->website7->add->add new item->visual c#->web form->file name -> home-
> click add.
8.toolbox->data->sql data source->configure data source->select database1.mdf->next-> set
dbconnect ->test query -> finish.

9.toolbox ->Gridview ->Auto format->choose data source->select oceanic->run the program.

Program:

Default .aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"


Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<br />
<br />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="NAME:"></asp:Label>
<asp:TextBox ID="TextBoxname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBoxname" Display="Dynamic" ErrorMessage="Enter name"
ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
<br />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="PWD:"></asp:Label>
<asp:TextBox ID="TextBoxpwd" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBoxpwd" Display="Dynamic" ErrorMessage="enter pwd"
ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
<br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="AGE:"></asp:Label>
<asp:TextBox ID="TextBoxage" runat="server" TextMode="Number"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBoxage" Display="Dynamic" ErrorMessage="Enter valid age"
ForeColor="Red" MaximumValue="60" MinimumValue="20" SetFocusOnError="True"
Type="Integer"></asp:RangeValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="submit"
Width="141px" />
<br />
<br />

</div>
</form>
</body>
</html>

Web.config:

<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="dbconnect" connectionString="Data
Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated
Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
</configuration>

Default.aspx.cs

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

}
protected void Button1_Click(object sender, EventArgs e)
{
try{
SqlConnection con=new
SqlConnection(ConfigurationManager.ConnectionStrings["dbconnect"].ConnectionString);
con.Open();
string insert ="insert into stud(name,pwd,age)values(@name,@pwd,@age)";
SqlCommand cmd = new SqlCommand(insert,con);
cmd.Parameters.AddWithValue("@name",TextBoxname.Text);
cmd.Parameters.AddWithValue("@pwd",TextBoxpwd.Text);
cmd.Parameters.AddWithValue("@age",TextBoxage.Text);
cmd.ExecuteNonQuery();
Response.Redirect("homepage.aspx");
con.Close();
}
catch(Exception ex)
{
Response.Write(ex);
}
}
}

Output:
Result:

Thus the web application to input data through a web form to a database and validate the data
was completed and output verified successfully.
Ex.No : 13 READING XML STUDENT DATABASE

Date :

Aim:

Develop a Windows application to read an XML document containing subject, marks scored,
year of passing into a dataSet.

Procedure:

1. Open Microsoft Visual Studio and create a new windows application with the name
StudentXml.

2. On the Project Menu click Add New Item and then click Xml File option.

3. Enter the filename as student.xml and click Add button. Now edit the following XML code.

<?xml version="1.0" encoding="utf-8" ?>


<student>
<stud>
<name> Martin </name>
<subject> Civil </subject>
<marks> 567 </marks>
<year> 2012 </year>
</stud>
<stud>
<name> Jeba </name>
<subject> ECE </subject>
<marks> 480 </marks>
<year> 2017 </year>
</stud>
<stud>
<name> Banu </name>
<subject> CSE </subject>
<marks> 520 </marks>
<year> 2014 </year>
</stud>
</student>

4.On File menu click Save student.xml option.

5. On Form1 add one Button control and a DataGridView control from the toolbox.
6. Change the Text property of Button1 as Show Table

7. On Form1 add a DataSet control from the toolbox.In the AddDataSet dialogue box, select
Untyped Dataset option and then click OK. Now DataSet1 is added to the component tray.

8. Set the Name and DataSetName properties as studentdataset

9. Edit the following C# code in the click event of Button1

String filePath="D:\\student.xml";
studentdataset.ReadXml(filePath);
dataGridView1.DataSource=studentdataset;
dataGridView1.DataMember="stud";

10. Run the Application

Output:

Result:

Thus the application to read an XML document containing subject, marks scored, year of
passing into a dataSet was completed and output verified successfully.
Ex.No : 14 GENERATING STUDENT XML DOCUMENT USING ADO.NET

Date :

Aim:

Develop a windows application to read students records from database using ADO.NET and
generate XML document containing students record.

Procedure:

1.Open Microsoft SQL Server and Create a table stud in student database by using the following
commands

create database student4

use student4

create table stud1(sname varchar(20), dept varchar(10), mark number(3))

insert into stud1 values(‘Joshy’,”EEE’,95)

insert into stud1values(‘Nisha’,”I.T.’,100)

2. Open Microsoft Visual studio File ->New->Project

3. Select project type as Visual c# -> Windows and Template type as Windows application, then
click OK.

4. Design a form with a button control as shown in figure


5. Insert the necessary codes to the form and Run the application.

Program

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.Xml;
using System.Data.SqlClient;

namespace EX14
{
public partial class Form1 : Form
{
public SqlConnection con;
public SqlDataReader rd;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
con = new SqlConnection("Data Source=CT-37\\SQLEXPRESS;Initial
Catalog=STUDENT4;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from stud1", con);
DataSet ds = new DataSet();
da.Fill(ds);
ds.WriteXml("stud1.xml");
MessageBox.Show("Xml document generated successfully");

}
}
}
OUTPUT:

Result:

Thus the windows application to read students records from database using ADO.NET and
generating XML document containing students record was completed and output verified
successfully.

You might also like