Problem Statement

You are required to implement web form for New Customer Regestration for Pine Valley furniture Company. Who will be the user of this form?

Solution:

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

<!DOCTYPE html>
<html>
<head runat="server">
    <title>Add New Customer</title>
    <style>
        .form-group { margin-bottom: 10px; }
        label { display: inline-block; width: 100px; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h2>Customer Entry Form</h2>
            <div class="form-group">
                <label>ID:</label> <asp:TextBox ID="txtId" runat="server"></asp:TextBox>
            </div>
            <div class="form-group">
                <label>Name:</label> <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            </div>
            <div class="form-group">
                <label>Address:</label> <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
            </div>
            <div class="form-group">
                <label>City:</label> <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
            </div>
            <div class="form-group">
                <label>State:</label> <asp:TextBox ID="txtState" runat="server"></asp:TextBox>
            </div>
            <div class="form-group">
                <label>Postal Code:</label> <asp:TextBox ID="txtZip" runat="server"></asp:TextBox>
            </div>
            <br />
            <asp:Button ID="btnSubmit" runat="server" Text="Save Customer" />
            <br /><br />
            <asp:Label ID="status" runat="server" Text=""></asp:Label>
        </div>
    </form>
</body>
</html>
                
Default.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Reflection.Emit
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Return

    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        Dim conn As SqlConnection
        conn = New SqlConnection

        'Dim constr As String = "Server=localhost;Database=PVFC;Trusted_Connection=True;"
        Dim constr As String = "workstation id=IAD_Lab_DB.mssql.somee.com;packet size=4096;user id=afzaalahmad_SQLLogin_1;pwd=5kvkluvzd7;data source=IAD_Lab_DB.mssql.somee.com;persist security info=False;initial catalog=IAD_Lab_DB;TrustServerCertificate=True"
        conn.ConnectionString = constr

        Dim cmd As SqlCommand = New SqlCommand
        cmd.Connection = conn

        cmd.CommandText = "INSERT INTO CUSTOMER_T (CUSTOMER_ID, CUSTOMER_NAME, CUSTOMER_ADDRESS, CUSTOMER_CITY, CUSTOMER_STATE, POSTAL_CODE) "
        cmd.CommandText &= "VALUES "

        cmd.CommandText &= "(" & txtId.Text & ", "
        cmd.CommandText &= "'" & txtName.Text & "', "
        cmd.CommandText &= "'" & txtAddress.Text & "', "
        cmd.CommandText &= "'" & txtCity.Text & "', "
        cmd.CommandText &= "'" & txtState.Text & "', "
        cmd.CommandText &= "'" & txtZip.Text & "')"

        Dim inserted As Integer = 0

        Try
            conn.Open()
            inserted = cmd.ExecuteNonQuery()
            If inserted = 1 Then
                status.Text = inserted & " customer record inserted."
            Else
                status.Text = "no record inserted"
            End If
        Catch ex As Exception
            status.Text = ex.Message

        Finally
            cmd.Dispose()
            conn.Close()
        End Try

    End Sub
End Class
                

Output:

Customer table before addition
image of display page
Customer table after addition
Web hosting by Somee.com