Professional Documents
Culture Documents
AWP Practical 7
AWP Practical 7
Practical 7
Working with Database
7a.aspx-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="7a.aspx.cs" Inherits="_7a" %>
<!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">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="VALUE" />
<br /><br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataTextField="name"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</div>
</form>
</body>
</html>
Design-
Page 1|8
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
7a.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.SqlClient;
public partial class _7a : System.Web.UI.Page
{
String str;
SqlConnection cn = new SqlConnection("Data Source=VICKY-PC;Initial
Catalog=studentdetails;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(DropDownList1.SelectedItem);
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from stud_dtls", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
}
Output-
Page 2|8
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
7b.aspx-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="7b.aspx.cs" Inherits="_7b" %>
<!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">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
</div>
</form>
</body>
</html>
Design-
7b.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.SqlClient;
public partial class _7b : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=vicky-PC;Initial
Catalog=aut_det;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from author_details where id=" +
TextBox1.Text + "", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox2.Text = Convert.ToString(dr["phoneno"]);
}
}
}
Page 4|8
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
Output-
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Insert" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Delete" />
<br />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Design-
7c.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.SqlClient;
public partial class _7c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("Data Source=VICKY-PC;Initial
Catalog=studentdetails;Integrated Security=True");
SqlCommand cmd = new SqlCommand("insert into stud_dtls values('" + TextBox1.Text +
"','" + TextBox2.Text + "')", cn);
cn.Open();
cmd.ExecuteNonQuery();
Label3.Text = "Data inserted successfully";
Page 6|8
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("Data Source=VICKY-PC;Initial
Catalog=studentdetails;Integrated Security=True");
SqlCommand cmd = new SqlCommand("delete from stud_dtls where id=" + TextBox1.Text
+ "", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
Label3.Text = "Data deleted successfully";
}
}
Output-
Page 7|8
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
Page 8|8