0% found this document useful (0 votes)
167 views

AWP Practical 6

This document contains instructions for three practical programming exercises involving databases in ASP.NET web applications. The first exercise involves creating an application that binds data from a database query into a multiline textbox when a button is clicked. The second displays records from a database table on a web page. The third demonstrates using a DataList control bound to a SQL data source to display database records. Code snippets and expected outputs are provided for each programming exercise.

Uploaded by

sushil
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)
167 views

AWP Practical 6

This document contains instructions for three practical programming exercises involving databases in ASP.NET web applications. The first exercise involves creating an application that binds data from a database query into a multiline textbox when a button is clicked. The second displays records from a database table on a web page. The third demonstrates using a DataList control bound to a SQL data source to display database records. Code snippets and expected outputs are provided for each programming exercise.

Uploaded by

sushil
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/ 7

T.Y.B.SC(I.T.

)-ADVANCED WEB PROGRAMMING-PAPER(III)


IT-7239
2018-2019

Practical 6
Working with Database

A) Create a web application bind data in a multiline textbox by querying in


another textbox.

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-

After clicking on Submit button-

Page 2|7
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019

B) Create a web application to display records by using database.


Program-
6b.aspx-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="6b.aspx.cs" Inherits="_6b" %>
<!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">
<p><b>EmpID FirstName LastName Age</b></p>
<asp:Label ID="Label1" runat="server" Height="250px" Width="250px"></asp:Label>
</div>
</form>
</body>
</html>

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

C) Demonstrate the use of Datalist link control.


Program-
6c.aspx-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="6c.aspx.cs" Inherits="_6c" %>
<!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:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
<br />
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
<br /><br />
</ItemTemplate>
</asp:DataList>
<br /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentdetailsConnectionString %>"
SelectCommand="SELECT * FROM [stud_dtls]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

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

You might also like