AWP Practical 6
AWP Practical 6
AWP Practical 6
Practical 6
Working with Database
Program-
Default.aspx-
<%@ 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">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
<asp:TextBox ID="TextBox1" runat="server" Text="<%# str %>"
TextMode="MultiLine"></asp:TextBox>
</form>
</body>
</html>
Design-
Default.aspx.cs-
using System;
using System.Collections.Generic;
using System.Linq;
Page 1|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected 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 Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from stud_dtls", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
str += dr["id"] + " " + dr["name"] + "\n";
}
this.DataBind();
}
}
Output-
Page 2|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
Design-
Page 3|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
6b.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 _6b : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=vicky-PC;Initial
Catalog=emp_details;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from emp_dtls", cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text += dr["empid"] + " " + dr["firstname"] + " " + dr["lastname"] + " " + dr["age"] +
"<br>";
}
}
}
Output-
Page 4|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
Design-
Page 5|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
6c.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 _6c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Output-
Page 6|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019
Page 7|7