Imports System.Data.SqlClient
Imports System.Collections.Generic

Public Class CustomerDB

    Private ConnectionString As String = _
    "Data Source=W2000;Initial Catalog=Northwind;Integrated Security=SSPI"

    Public Function GetCustomers() As List(Of CustomerDetails)
        Dim Sql As String = "SELECT * FROM Customers"

        Dim con As New SqlConnection(ConnectionString)
        Dim cmd As New SqlCommand(Sql, con)
        Dim Reader As SqlDataReader
        Dim Customers As New List(Of CustomerDetails)
        Try
            con.Open()
            Reader = cmd.ExecuteReader()
            Do While Reader.Read()
                Dim Customer As New CustomerDetails()
                Customer.ID = Reader("CustomerID").ToString()
                Customer.Name = Reader("ContactName").ToString()
                Customers.Add(Customer)
            Loop
        Catch Err As Exception
            Throw New ApplicationException( _
             "Exception encountered when executing command.", Err)
        Finally
            con.Close()
        End Try

        Return Customers
    End Function

End Class

Public Class CustomerDetails

    Private _ID As String
    Private _Name As String

    Public Property ID() As String
        Get
            Return _ID
        End Get
        Set(ByVal Value As String)
            _ID = Value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal Value As String)
            _Name = Value
        End Set
    End Property

End Class

