Lab 4B Report

Web Form: Customer.aspx

Problem Statement

The objective of this task was to create an ASP.NET Web Forms application using Visual Studio and SQL Server. A form named Customer.aspx was developed to retrieve and display customer data from the 'Customer' table stored on a remote SQL Server database. The form connects to the database, fetches data, and binds it to a GridView for presentation.

Code Implementation

Customer.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Customer.aspx.vb" Inherits="Customer" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Customer Directory</title>
    <style>
        body {
            font-family: 'Segoe UI', sans-serif;
            background-color: #f0f4f8;
            color: #333;
        }
        header {
            background-color: #2c3e50;
            color: white;
            text-align: center;
            font-size: 32px;
            padding: 20px;
        }
        .grid-style th {
            background-color: #2c3e50;
            color: white;
        }
        .grid-style td {
            background-color: #fff;
            padding: 10px;
        }
        .grid-style tr:hover td {
            background-color: #e8f0fe;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <header>Customer Records</header>
        <h2>Registered Customers</h2>
        <asp:GridView ID="CustomerGrid" runat="server" AutoGenerateColumns="true" CssClass="grid-style" />
    </form>
</body>
</html>

Customer.aspx.vb

Imports System.Data
Imports System.Data.SqlClient

Partial Class Customer
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            FetchTopCustomers()
        End If
    End Sub

    Private Sub FetchTopCustomers()
        Dim connString As String = "workstation id=aamiroon.mssql.somee.com;packet size=4096;user id=Aamiroon_Ishaq_SQLLogin_1;pwd=********;data source=aamiroon.mssql.somee.com;persist security info=False;initial catalog=aamiroon;TrustServerCertificate=True"
        Dim sqlQuery As String = "SELECT * FROM Customer"

        Using connection As New SqlConnection(connString),
              adapter As New SqlDataAdapter(sqlQuery, connection)

            Dim customersTable As New DataTable()
            adapter.Fill(customersTable)
            CustomerGrid.DataSource = customersTable
            CustomerGrid.DataBind()
        End Using
    End Sub
End Class

Sample Output

The following GridView is rendered on the browser after fetching data from the SQL Server database: