This code demonstrates how to display the first five customer records from a SQL Server database using ASP.NET and GridView.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Customer.aspx.vb" Inherits="Customer" %> <!-- Customer.aspx --> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"></asp:GridView> ' 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 BindCustomerData() End If End Sub Private Sub BindCustomerData() Dim connectionString As String = "your_connection_string_here" Dim query As String = "SELECT TOP 5 Customer_ID, Customer_Name, Customer_HouseNo, Customer_Street, Customer_ZipCode, Customer_Phone FROM Customer" Using connection As New SqlConnection(connectionString) Using command As New SqlCommand(query, connection) Dim adapter As New SqlDataAdapter(command) Dim dataTable As New DataTable() adapter.Fill(dataTable) GridView1.DataSource = dataTable GridView1.DataBind() End Using End Using End Sub End Class