0% found this document useful (0 votes)
12 views6 pages

Practical No. 6

The document outlines practical exercises for an Advanced Web Programming course, focusing on creating web applications that interact with databases. It includes code examples for binding data to textboxes, displaying records using a ListBox, and demonstrating the use of a DataList control. Each section provides a specific aim, code implementation, and expected output format.
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)
12 views6 pages

Practical No. 6

The document outlines practical exercises for an Advanced Web Programming course, focusing on creating web applications that interact with databases. It includes code examples for binding data to textboxes, displaying records using a ListBox, and demonstrating the use of a DataList control. Each section provides a specific aim, code implementation, and expected output format.
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/ 6

TY-BSCIT SUBJECT: Advanced Web Programming

Practical No. 6

A. Aim: Create a web application bind data in a multiline textbox by


querying in another textbox.
Code:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace p6a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs


e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=JCC-
GIGABYTE;Initial Catalog=TYIT;Integrated Security = True";
//stringconnStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionSt
ring;
//SqlCommand cmd = new SqlCommand("Select
Id,Name,Password from Login", conn);
SqlCommand cmd = new SqlCommand(TextBox1.Text,
conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
TextBox2.Text += reader["ID"].ToString() + " "
+ reader["Name"].ToString() + " "
+ reader["Password"].ToString() + "\n";
}

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming
reader.Close();
conn.Close();
}
}
}

Output:

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming
B. Create a web application to display records by using database.
Code:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=JCC-GIGABYTE;Initial
Catalog=tyit;Integrated Security = True";
//stringconnStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionSt
ring;
//SqlCommand cmd = new SqlCommand("Select * from City",
conn);
SqlCommand cmd = new SqlCommand(TextBox1.Text, conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
//To add new blank line in the text area
for (int i = 0; i < reader.FieldCount - 1; i++)
{
ListBox1.Items.Add(reader[i + 1].ToString());
}
}
reader.Close();
conn.Close();
}

Output:

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming
C. Demonstrate the use of Datalist link control.
CODE:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="p6c.WebForm1" %>

<!DOCTYPE html>

<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>
CITY:
<asp:Label ID="CITYLabel" runat="server"
Text='<%# Eval("CITY") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:tyitConnectionString3 %>"
ProviderName="<%$
ConnectionStrings:tyitConnectionString3.ProviderName %>"
SelectCommand="SELECT * FROM [City]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming

SEM-V Roll no.: 711


TY-BSCIT SUBJECT: Advanced Web Programming

OUTPUT:

SEM-V Roll no.: 711

You might also like