Awp Practicals
Awp Practicals
Practical No.6(a)
Problem Statement :- create a web application to bind data in a multiline textbox by querying in
another textbox
Database project :
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>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data
Source=’SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf ‘;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Practical6(a).aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Practical6(a).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;
}
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();
}
}
Connection :
Create table :
Note : As above practical6(a) we had create one database connection and table also using this one
in further practica6(b)..and so on
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>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Source code :
practical6(b).aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
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;
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
while (reader.Read())
{
Label2.Text += reader["sid"].ToString() + "" + reader["sname"].ToString() + "<br>";
}
reader.Close();
con.Close();
}
}
Output :
Source code :
practical6(c).aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:DataList ID="DataList1" runat="server">
</asp:DataList>
</form>
</body>
</html>
Step 1:
Step 2 :
Note :In that The Databinding to DropDownList can be done using visual studio options to select
the Data Source, The step is similar as performed in practical6(c)
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>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Practical7(a).aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
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;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
con.Open();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "sname";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "The name you selected is :" + DropDownList1.SelectedValue;
}
}
Note :The output can become either two way one is through coding in .cs file
Problem statement :- Create a web application for to display the marks of students using
database.
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>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Source code :
Practical7(b).aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Practical7(b).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;
con.Open();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "sname";
DropDownList1.DataValueField = "smarks";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}
Design…prctical7(b):
1.Through coding
..OR..
Step 1 :
Step2:
Step 3:
Step4:
Step 5 :
Step 6:
Step 7:
Step8:
Step 9 :
1)
Output :
Practical No.7(c)
Problem Statement :- Create a web application for inserting and deleting record from a database.
(Using Execute –Non Query).
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>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Source code :
Practical7(c).aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Practical7(c).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;
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "insert into stud values(@sid,@sname,@smarks)";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@sid", TextBox1.Text);
cmd.Parameters.AddWithValue("@sname", TextBox2.Text);
cmd.Parameters.AddWithValue("@smarks", TextBox3.Text);
con.Open();
cmd.ExecuteNonQuery();
Label4.Text = "Recored Inserted Successfully";
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 stud where sid=@sid";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@sid", TextBox1.Text);
// cmd.Parameters.AddWithValue("@sname", TextBox2.Text);
// cmd.Parameters.AddWithValue("@smarks", TextBox3.Text);
con.Open();
cmd.ExecuteNonQuery();
Design..practical7(c) :
Table :
Output :
Practical No.8(a)
Source code :
8a.aspx.cs :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Output:
PracticalNo.8(b)
Problem statements :- Create a web application to demonstrate data binding using Details View
and Form View Control
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>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Source code :
Practical8(b).aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\
Data.mdf;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [stud]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Design …practical8(b):
After adding the controls,configure the Data Source property of these controls in similar
manner as explained in practical 6(a)
Output :
Practical No.8(c)
Problem Statement :-Create a web application to display Using Disconnected Data Access and
Databinding using Gridview
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>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>
Source code :
Practical8(c).aspx :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Practical8(c).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;
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlDataAdapter objDa = new SqlDataAdapter();
DataSet objDas = new DataSet();
using (SqlConnection objConn = new SqlConnection(connStr))
{
SqlCommand objCmd = new SqlCommand("select * from stud", objConn);
objCmd.CommandType= CommandType.Text;
}
}
Design ….practical8(c):
Output :
1)
Practical No :9(a)
Source code :
9a.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="9a.aspx.cs"Inherits="_9a"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkFieldDataTextField="sid"HeaderText="Student Id"
NavigateUrl="~/7a.aspx"/>
<asp:BoundFieldDataField="sname"HeaderText="Student Name"
SortExpression="sname"/>
<asp:BoundFieldDataField="smarks"HeaderText="Student Marks"
SortExpression="smarks"/>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"
ConnectionString="<%$ConnectionStrings:ConnectString%>"
SelectCommand="SELECT * FROM [student]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Design….9(a)
Output:
Practical No.10(a)
Problem statements : Create a web application to demonstrate reading and writing operation
with XML.
1) abc.xml
Source code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Design:
10a.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
Vacation\\PRACT6\\abc", null);
writer.WriteStartDocument();
writer.WriteStartElement("names");
writer.WriteElementString("name", "kiran");
writer.WriteElementString("name", "pramod");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
red.Close();
}
}
Output:
Practical no:11
class1.cs dll:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1
publicclassClass1
{
int c = a + b;
return c;
program.cs:
using System;
usingSystem.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dll
{
classProgram
{
Static void Main(string[] args)
{
Console.ReadKey();
Output :